medialab/sandcrawler · spawn.js
javascript logo
function(spider, callback) {
  var self = this;

  if (!types.check(spider, 'spider'))
    throw Error('sandcrawler.spawn.run: given argument is not a valid spider.');

  if (spider.state.fulfilled)
    throw Error('sandcrawler.spawn.run: given spider has already been fulfilled.');

  if (spider.state.running)
    throw Error('sandcrawler.spawn.run: given spider has already running.');

  // Registering
  this.spiders.push(spider.id);

  // Running given spider
  spider.engine.phantom = this.spy;
  spider._start(function(err, remains) {

    // Removing spiders from list
    _.pullAt(self.spiders, self.spiders.indexOf(spider.id));

    // Autoclosing the spawn?
    if (self.params.autoClose && !self.spiders.length)
      self.close();

    if (typeof callback !== 'function')
      return;

    if (err)
      return callback(err, remains);

    callback(null, remains);
  });
}
Similar code snippets
1.
medialab/sandcrawler · throttle.js
Match rating: 57.22% · See similar code snippets
javascript logo
function(spider) {

    spider.beforeScraping(function(req, next) {
      if (!this.index)
        return next();

      var time = max ? randomNumber(min, max) : min + Math.random();

      setTimeout(next, time);
    });
  }
2.
openphacts/ops.js · CompoundSearch.js
Match rating: 56.94% · See similar code snippets
javascript logo
function(chemspiderBlock) {
    var constants = new Constants();
    var URI = null,
        hba = null,
        hbd = null,
        inchi = null,
        logp = null,
        psa = null,
        ro5Violations = null,
        smiles = null,
        fullMWT = null,
        molform = null,
        rtb = null,
        inchiKey = null,
        molform = null;
    var chemspiderData = chemspiderBlock;
    var chemspiderProvenance = {};
    var chemspiderLinkOut = null;

    URI = chemspiderData["_about"] !== null ? chemspiderData["_about"] : URI;
    hba = chemspiderData.hba != null ? chemspiderData.hba : hba;
    hbd = chemspiderData.hbd != null ? chemspiderData.hbd : hbd;
    inchi = chemspiderData.inchi != null ? chemspiderData.inchi : inchi;
    logp = chemspiderData.logp != null ? chemspiderData.logp : logp;
    psa = chemspiderData.psa != null ? chemspiderData.psa : psa;
    ro5Violations = chemspiderData.ro5_violations != null ? chemspiderData.ro5_violations : ro5Violations;
    smiles = chemspiderData.smiles != null ? chemspiderData.smiles : smiles;
    inchiKey = chemspiderData.inchikey != null ? chemspiderData.inchikey : null;
    rtb = chemspiderData.rtb != null ? chemspiderData.rtb : rtb;
    fullMWT = chemspiderData.molweight != null ? chemspiderData.molweight : null;
    molform = chemspiderData.molformula != null ? chemspiderData.molformula : null;

    // provenance 
    chemspiderLinkOut = URI;
    chemspiderProvenance = {};
    chemspiderProvenance['source'] = 'chemspider';
    chemspiderProvenance['hba'] = chemspiderLinkOut;
    chemspiderProvenance['hbd'] = chemspiderLinkOut;
    chemspiderProvenance['inchi'] = chemspiderLinkOut;
    chemspiderProvenance['logp'] = chemspiderLinkOut;
    chemspiderProvenance['psa'] = chemspiderLinkOut;
    chemspiderProvenance['ro5violations'] = chemspiderLinkOut;
    chemspiderProvenance['smiles'] = chemspiderLinkOut;
    chemspiderProvenance['inchiKey'] = chemspiderLinkOut;
    chemspiderProvenance['molform'] = chemspiderLinkOut;
    return {
        "URI": URI,
        "hba": hba,
        "hbd": hbd,
        "inchi": inchi,
        "logp": logp,
        "psa": psa,
        "ro5Violations": ro5Violations,
        "smiles": smiles,
        "fullMWT": fullMWT,
        "molform": molform,
        "rtb": rtb,
        "inchiKey": inchiKey,
        "chemspiderProvenance": chemspiderProvenance
    };

}
3.
codemirror/CodeMirror · spans.js
Match rating: 55.61% · See similar code snippets
javascript logo
function lineIsHidden(doc, line) {
  let sps = sawCollapsedSpans && line.markedSpans
  if (sps) for (let sp, i = 0; i < sps.length; ++i) {
    sp = sps[i]
    if (!sp.marker.collapsed) continue
    if (sp.from == null) return true
    if (sp.marker.widgetNode) continue
    if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
      return true
  }
}
4.
ungap/url-search-params · index.js
Match rating: 52.51% · See similar code snippets
javascript logo
function (sp) {
        var append = sp.append;
        sp.append = URLSearchParamsProto.append;
        URLSearchParams.call(sp, sp._usp.search.slice(1));
        sp.append = append;
      }
5.
ionic-team/legacy-ionic-cloud · insights.spec.js
Match rating: 50.12% · See similar code snippets
javascript logo
function() {

  var i;
  var appStatusSpy;
  var storageSpy;
  var configSpy;
  var clientSpy;
  var deviceSpy;
  var loggerSpy;

  function instantiateWithOptions(options) {
    return new insights.Insights({
      'appStatus': appStatusSpy,
      'storage': storageSpy,
      'config': configSpy,
      'client': clientSpy,
      'device': deviceSpy,
      'logger': loggerSpy
    }, options);
  }

  beforeEach(function() {
    jasmine.clock().install();
    jasmine.clock().mockDate();

    appStatusSpy = {};
    storageSpy = jasmine.createSpyObj('storageSpy', ['get', 'set']);
    configSpy = new Config();
    clientSpy = {};
    deviceSpy = {};
    loggerSpy = jasmine.createSpyObj('loggerSpy', ['info', 'warn', 'error']);

    appStatusSpy.closed = false;
    configSpy.register({ 'core': { 'app_id': 'abcd' } });
  });

  afterEach(function() {
    jasmine.clock().uninstall();
  });

  it("should instantiate", function() {
    i = instantiateWithOptions();
    expect(i.options.intervalSubmit).toBe(60 * 1000);
    expect(i.options.intervalActiveCheck).toBe(1000);
    expect(i.options.submitCount).toBe(100);
  });

  it("should call submit on submit interval", function() {
    i = instantiateWithOptions({ 'intervalActiveCheck': false });
    spyOn(i, "submit");
    expect(i.submit).not.toHaveBeenCalled();
    jasmine.clock().tick(i.options.intervalSubmit);
    expect(i.submit).toHaveBeenCalledTimes(1);
    jasmine.clock().tick(i.options.intervalSubmit);
    expect(i.submit).toHaveBeenCalledTimes(2);
  });

  it("should check activity on active check interval", function() {
    i = instantiateWithOptions({ 'intervalSubmit': false });
    spyOn(i, "checkActivity");
    expect(i.checkActivity).not.toHaveBeenCalled();
    jasmine.clock().tick(i.options.intervalActiveCheck);
    expect(i.checkActivity).toHaveBeenCalledTimes(1);
    jasmine.clock().tick(i.options.intervalActiveCheck);
    expect(i.checkActivity).toHaveBeenCalledTimes(2);
  });

  it("should mark active immediately", function() {
    i = instantiateWithOptions({ 'intervalSubmit': false });
    spyOn(i, "markActive");
    jasmine.clock().tick(i.options.intervalActiveCheck);
    expect(i.markActive).toHaveBeenCalled();
  });

  it("should mark active immediately and then again every hour", function() {
    i = instantiateWithOptions({ 'intervalSubmit': false });
    spyOn(i, "markActive");
    jasmine.clock().tick(i.options.intervalActiveCheck);
    expect(i.markActive).toHaveBeenCalledTimes(1);
    i.storage.get.and.returnValue(String(new Date()));
    jasmine.clock().tick(60 * 60 * 1000);
    expect(i.markActive).toHaveBeenCalledTimes(2);
    i.storage.get.and.returnValue(String(new Date()));
    jasmine.clock().tick(60 * 60 * 1000);
    expect(i.markActive).toHaveBeenCalledTimes(3);
  });

  it("should normalize device platforms", function() {
    i = instantiateWithOptions({ 'intervalSubmit': false, 'intervalActiveCheck': false });
    expect(i.normalizeDevicePlatform('Android')).toBe('android');
    expect(i.normalizeDevicePlatform('iOS')).toBe('ios');
    expect(i.normalizeDevicePlatform('Mac OS X')).toBe('mac_os_x');
  });

  it("should normalize versions", function() {
    i = instantiateWithOptions({ 'intervalSubmit': false, 'intervalActiveCheck': false });
    expect(i.normalizeVersion('2.2')).toBe('2');
    expect(i.normalizeVersion('2.1-update1')).toBe('2');
    expect(i.normalizeVersion('6.0.0.600')).toBe('6');
    expect(i.normalizeVersion('TIZEN_20120425_2')).toBe('unknown');
  });

  it("should track active stats", function() {
    i = instantiateWithOptions({ 'intervalSubmit': false, 'intervalActiveCheck': false });
    i.device.native = { 'platform': 'Android', 'version': '2.2', 'cordova': '6.2.1' };
    expect(i.batch).toEqual([]);
    i.markActive();

    var collectedStats = i.batch.map(function(stat) {
      return stat.stat;
    });

    expect(collectedStats.length).toBe(4);
    expect(collectedStats).toEqual(jasmine.arrayContaining([
      'mobileapp.active',
      'mobileapp.active.platform.android',
      'mobileapp.active.platform.android.2',
      'mobileapp.active.cordova.6'
    ]));
  });

}
6.
angular/material · gesture.spec.js
Match rating: 50.06% · See similar code snippets
javascript logo
function() {
    var now;
    var leftSpy;
    var rightSpy;
    var upSpy;
    var downSpy;
    var el;

    beforeEach(function () {
      now = 0;

      spyOn(Date, 'now').and.callFake(function() { return now; });

      leftSpy = jasmine.createSpy('left');
      rightSpy = jasmine.createSpy('right');
      upSpy = jasmine.createSpy('up');
      downSpy = jasmine.createSpy('down');
      el = angular.element('<div>');

      el.on('$md.swipeleft', leftSpy)
        .on('$md.swiperight', rightSpy)
        .on('$md.swipeup', upSpy)
        .on('$md.swipedown', downSpy);

    });

    it('should swipeleft if velocityX > minVelocity and distanceX > maxDistance', inject(function($mdGesture, $document) {
      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      now = 1;
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: -100, pageY: 0
      });
      expect(leftSpy).toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      var pointer = leftSpy.calls.mostRecent().args[0].pointer;
      expect(pointer.velocityX).toBe(-100);
      expect(pointer.distanceX).toBe(-100);
    }));

    it('should swiperight if velocityX > minVelocity and distanceX > maxDistance', inject(function($mdGesture, $document) {
      $document.triggerHandler('$$mdGestureReset');
      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      now = 1;
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: 100, pageY: 0
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      var pointer = rightSpy.calls.mostRecent().args[0].pointer;
      expect(pointer.velocityX).toBe(100);
      expect(pointer.distanceX).toBe(100);

    }));

    it('should swipeup if velocityY > minVelocity and distanceY > maxDistance', inject(function($mdGesture, $document) {
      $document.triggerHandler('$$mdGestureReset');
      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      now = 1;
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: 0, pageY: -100
      });
      expect(upSpy).toHaveBeenCalled();
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      var pointer = upSpy.calls.mostRecent().args[0].pointer;
      expect(pointer.velocityY).toBe(-100);
      expect(pointer.distanceY).toBe(-100);
    }));

    it('should swipedown if velocityY > minVelocity and distanceY > maxDistance', inject(function($mdGesture, $document) {
      $document.triggerHandler('$$mdGestureReset');
      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      now = 1;
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: 0, pageY: 100
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).toHaveBeenCalled();

      var pointer = downSpy.calls.mostRecent().args[0].pointer;
      expect(pointer.velocityY).toBe(100);
      expect(pointer.distanceY).toBe(100);

    }));

    it('should not swipeleft when velocity is too low', inject(function($document) {
      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      // 100ms and 50 distance = velocity of 0.5, below the boundary. no swipe.
      now = 100;
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: -50, pageY: 0
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      // 101ms and 100 distance = velocity of 1.0001, just fast enough for a swipe.
      now = 101;
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: -100, pageY: 0
      });
      expect(leftSpy).toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();
    }));

    it('should not swiperight when distance is too low', inject(function($document) {
      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      now = 1;
      // 10 distance = boundary. no swipe.
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: 10, pageY: 0
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      // 11 distance = enough. swipe.
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: 11, pageY: 0
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();
    }));

    it('should not swipeup when velocity is too low', inject(function($document) {
      $document.triggerHandler('$$mdGestureReset');
      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      // 100ms and 50 distance = velocity of 0.5, below the boundary. no swipe.
      now = 100;
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: 0, pageY: -50
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      // 101ms and 100 distance = velocity of 1.0001, just fast enough for a swipe.
      now = 101;
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: 0, pageY: -100
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();
    }));

    it('should not swipedown when velocity is too low', inject(function($document) {
      $document.triggerHandler('$$mdGestureReset');
      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      // 100ms and 50 distance = velocity of 0.5, below the boundary. no swipe.
      now = 100;
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: 0, pageY: 50
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).not.toHaveBeenCalled();

      $document.triggerHandler({
        type: 'touchstart', target: el[0], pageX: 0, pageY: 0
      });
      // 101ms and 100 distance = velocity of 1.0001, just fast enough for a swipe.
      now = 101;
      $document.triggerHandler({
        type: 'touchend', target: el[0], pageX: 0, pageY: 100
      });
      expect(leftSpy).not.toHaveBeenCalled();
      expect(rightSpy).not.toHaveBeenCalled();
      expect(upSpy).not.toHaveBeenCalled();
      expect(downSpy).toHaveBeenCalled();
    }));

  }
7.
facebook/flow · index.js
Match rating: 49.43% · See similar code snippets
javascript logo
function space(size) {
  var sp = ' ';
  var result = '';

  for (;;) {
    if ((size & 1) === 1) {
      result += sp;
    }
    size >>>= 1;
    if (size === 0) {
      break;
    }
    sp += sp;
  }
  return result;
}
8.
Nazariglez/perenquen · spineAtlasParser.js
Match rating: 49.31% · See similar code snippets
javascript logo
function (res)
        {
            // create a spine atlas using the loaded text
            var spineAtlas = new spine.SpineRuntime.Atlas(this.xhr.responseText, baseUrl, res.crossOrigin);

            // spine animation
            var spineJsonParser = new spine.SpineRuntime.SkeletonJsonParser(new spine.SpineRuntime.AtlasAttachmentParser(spineAtlas));
            var skeletonData = spineJsonParser.readSkeletonData(resource.data);

            resource.spineData = skeletonData;
            resource.spineAtlas = spineAtlas;

            // Go through each spineAtlas.pages and wait for page.rendererObject (a baseTexture) to
            // load. Once all loaded, then call the next function.
            async.each(spineAtlas.pages, function (page, done)
            {
                if (page.rendererObject.hasLoaded)
                {
                    done();
                }
                else
                {
                    page.rendererObject.once('loaded', done);
                }
            }, next);
        }
9.
ungap/url-search-params · index.js
Match rating: 49.26% · See similar code snippets
javascript logo
function (Object) {
    var
      dP = Object.defineProperty,
      gOPD = Object.getOwnPropertyDescriptor,
      createSearchParamsPollute = function (search) {
        function append(name, value) {
          URLSearchParamsProto.append.call(this, name, value);
          name = this.toString();
          search.set.call(this._usp, name ? ('?' + name) : '');
        }
        function del(name) {
          URLSearchParamsProto.delete.call(this, name);
          name = this.toString();
          search.set.call(this._usp, name ? ('?' + name) : '');
        }
        function set(name, value) {
          URLSearchParamsProto.set.call(this, name, value);
          name = this.toString();
          search.set.call(this._usp, name ? ('?' + name) : '');
        }
        return function (sp, value) {
          sp.append = append;
          sp.delete = del;
          sp.set = set;
          return dP(sp, '_usp', {
            configurable: true,
            writable: true,
            value: value
          });
        };
      },
      createSearchParamsCreate = function (polluteSearchParams) {
        return function (obj, sp) {
          dP(
            obj, '_searchParams', {
              configurable: true,
              writable: true,
              value: polluteSearchParams(sp, obj)
            }
          );
          return sp;
        };
      },
      updateSearchParams = function (sp) {
        var append = sp.append;
        sp.append = URLSearchParamsProto.append;
        URLSearchParams.call(sp, sp._usp.search.slice(1));
        sp.append = append;
      },
      verifySearchParams = function (obj, Class) {
        if (!(obj instanceof Class)) throw new TypeError(
          "'searchParams' accessed on an object that " +
          "does not implement interface " + Class.name
        );
      },
      upgradeClass = function (Class) {
        var
          ClassProto = Class.prototype,
          searchParams = gOPD(ClassProto, 'searchParams'),
          href = gOPD(ClassProto, 'href'),
          search = gOPD(ClassProto, 'search'),
          createSearchParams
        ;
        if (!searchParams && search && search.set) {
          createSearchParams = createSearchParamsCreate(
            createSearchParamsPollute(search)
          );
          Object.defineProperties(
            ClassProto,
            {
              href: {
                get: function () {
                  return href.get.call(this);
                },
                set: function (value) {
                  var sp = this._searchParams;
                  href.set.call(this, value);
                  if (sp) updateSearchParams(sp);
                }
              },
              search: {
                get: function () {
                  return search.get.call(this);
                },
                set: function (value) {
                  var sp = this._searchParams;
                  search.set.call(this, value);
                  if (sp) updateSearchParams(sp);
                }
              },
              searchParams: {
                get: function () {
                  verifySearchParams(this, Class);
                  return this._searchParams || createSearchParams(
                    this,
                    new URLSearchParams(this.search.slice(1))
                  );
                },
                set: function (sp) {
                  verifySearchParams(this, Class);
                  createSearchParams(this, sp);
                }
              }
            }
          );
        }
      }
    ;
    try {
      upgradeClass(HTMLAnchorElement);
      if (/^function|object$/.test(typeof URL) && URL.prototype)
        upgradeClass(URL);
    } catch (meh) {}
  }
10.
be5invis/libspiro-js · libspiro.js
Match rating: 48.98% · See similar code snippets
javascript logo
function spiroToBezierOnContext(spiros, isClosed, bc, isquad, delta) {
	var s;
	var n = spiros.length;
	if (n < 1) return;
	if (!isClosed) {
		var oldty_start = spiros[0].type;
		var oldty_end = spiros[n - 1].type;
		spiros[0].type = 'open';
		spiros[n - 1].type = 'open_end';
		s = run_spiro(spiros, n);
		spiros[n - 1].type = oldty_end;
		spiros[0].type = oldty_start;
	} else {
		s = run_spiro(spiros, n);
	}
	spiro_to_bpath(s, n, bc, isquad, delta);
}