Example #1
0
  }, function(error, res, body) {
    if (!error && res.statusCode == 200) {
      var things = JSON.parse(body); // array of strings.

      //NOTE: this is using case-sensitive comparison
      if (_options.onlyInclude) {
        things = _.select(things, function(thing) {
          return _options.onlyInclude.indexOf(thing.name) > -1;
        });
      }

      //NOTE: this is using case-sensitive comparison
      if (_options.exclude) {
        things = _.reject(things, function(thing) {
          return _options.exclude.indexOf(thing.name) > -1;
        });
      }

      var sem = things.length;

      _.each(things, function(thing) {
        client[thing.name] = buildClientApi(thing);
      });

      _cb(null, client);

    } else {
      _cb && _cb("Unable to retrieve available APIs from " + _options.url + ' due to: ' + require('util').inspect(error));
    }
  });
Example #2
0
		roomManager.getOrCreate(gameSlug, function(data) {
			console.log(data);
			var room = data;
			if(room) {
				if (!_.isUndefined(user.role) && user.role === 'student') {
					// student = author
					console.log(user.userName + ' is an author');
					// remove current user first
					roomAuthors = _.reject(room.authors, function(el) { return el.userName === user.userName; });
					if(roomAuthors.length < 4) {
						// max 4 authors per room
						user.socketId = socket.id;
					 	roomAuthors.push(user);
					 	room.authors = roomAuthors;
						socket.join(gameSlug);
						roomManager.setRoom(gameSlug, JSON.stringify(room), function(err, reply) {
			                console.log('Room updated');
				            socket.broadcast.to(gameSlug).emit('author:joined:room', {
						        user: user,
		        				socketId: socket.id
		      				});
			            });
					} else {
						//room.full
						room = null;
					}
				} else if (!_.isUndefined(user.role) && user.role === 'teacher') {
					// teacher
				}
			}
			// return room data to callback function	
			fn(room);
		});
Example #3
0
 emitter.on('relation', function(rel) {
     if (_.include(relations, rel)) {
         relations = _.reject(relations, rel);
     } else {
         cb(JSON.stringify(rel) + ' is not in list');
     }
 });
Example #4
0
 removeConnectedParticipant: function(user) {
     var participants = this.get("connectedParticipants");
     var newParticipants = _.reject(participants, function (u) {
         return u.id == user.id
     });
     return this.setConnectedParticipants(newParticipants);
 },
Example #5
0
	removeMatchFromQueue: function(match) {
		winston.info("Removing match id after completed or declined tweet: " + match.match_id);

		// winston.info("matches before: " + JSON.stringify(this.matchesToTweet));
		this.matchesToTweet = _.reject(this.matchesToTweet, function(m) {
			return m.match_id==match.match_id;
		});
		// winston.info("matches after: " + JSON.stringify(this.matchesToTweet));

		// remove the details cache too to keep it from accumulating.
		delete this.matchDetailsCache[match.match_id];

		// Make sure it's not in redis either. 99% of the time it won't be, but
		// we'll just make absolute sure here. It's a cheap operation and it fails
		// easily.
		if(this.redis) {
			winston.debug("Trying to remove " + match.match_id + " from delayed_matches.")
			this.redis.hdel("global:delayed_matches", match.match_id,
				function(err, reply) {
					if(err) {
						winston.warn("\tError removing match: " + err);
					}
					winston.info("\tRemoved " + reply + " matches.");
				});
		} else {
			winston.warn("No redis instance to remove match from.");
		}
	},
Example #6
0
function prepText(text) {
  if (_.isArray(text)) return text;
  var deduped = _.uniq(tokenizer.tokenize(text));
  if (!this.options.stopwords) return deduped;
  return _.reject(deduped, _.bind(isStopword, null,
      _.isString(this.options.stopwords) ? this.options.stopwords : natural_stopwords
      ));
}
Example #7
0
function optToFn() {
  var
    map = cmd === 'seek' ? POS_abbr : POS,
    fns = _.reject(map, function(fn, opt) { return !program[opt] });
  if (!fns.length && cmd === 'rand') return fns = ['']; // run rand()
  if (!fns.length) fns = _.values(map); //default to all if no POS given
  return fns;
}
Example #8
0
 emitter.on('way', function(way) {
     var elem = JSON.stringify(way);
     if (_.include(ways, elem)) {
        ways  = _.reject(ways, elem);
     } else {
         console.log(ways);
         cb(false, JSON.stringify(way) + ' is not in list');
     }
 });
Example #9
0
  remove: function(client) {
    var me = this;
    var removed = Channel.super.prototype.remove.call(this, client);
    if (removed && client.id !== me.channelClient.id) {
      var _uuid = me.clientUUIDs[client.id];
      delete me.clientUUIDs[client.id];
      delete me.crossIndexedClients[_uuid];
      me.clientsBySessionId[client.session.id] = _.reject(me.clientsBySessionId[client.session.id], function(_client){
        return _client === client;
      });

      if(!me.clientsBySessionId[client.session.id].length) {
        delete me.clientsBySessionId[client.session.id];
      }

      me.doHook("disconnect", {client: client}, function(err, hookData) {
        if (err && err !== nohook) {
          me.error(
            client, 
            {type: "Hook Error", message: "Disconnect error: " + err},
            {hook: "disconnect", error: err}
          );
        } else {
          var eventData = {
            type: "channel",
            channelId: me.id,
            message: "disconnection",
            data: {
              clientId: _uuid,
              data: hookData
            }
          };

          if (me.options.announceConnections) {
            //loop clients and send
            me.each(function(_client) {
              if (_client !== client
                  && _client.id !== me.channelClient.id) {
                _client.json.send(eventData);
              }
            });
          }

          //fire local event
          me.fire('disconnection', eventData);
        }
      });

      //lastly, tell the client it has successfully unsubscribed
      client.json.send({
        type: "channel",
        channelId: me.id,
        message: "unsubscribe"
      });
    }
  },
Example #10
0
            _.each(arr, function (elem) {
                if (elem.IsDeleted) {
                    skdUsers = _.reject(skdUsers, function (subElem) {
                        return subElem.Id == elem.Id;
                    });
                } else {

                    if (_.find(skdUsers, function (subElem) {
                        return subElem.Id == elem.Id;
                    }) == null) {
                        skdUsers.push(elem);
                    } else {
                        skdUsers = _.reject(skdUsers, function (subElem) {
                            return subElem.Id == elem.Id;
                        });
                        skdUsers.push(elem);
                    }
                }
            });
Example #11
0
 removeComponent: function(name) {
   if (this.components[name]) {
     var component = this.components[name];
     this.components[name] = null;
     this.componentOrder = _.reject(this.componentOrder, function(it) { return it === name; });
     if (component.watching) {
       fileWatcher.unwatchFile(name, component.changeListener);
     }
     this.fire('componentRemoved', name);
   }
 },
Example #12
0
 labdb.getOrCreateHomeLab(home.name, startLab, function(e, labInfo) {
   if (e) return sendError('Failed to get home lab', e);
   var newLabParts = _.reject(labInfo.labParts, function(labPart) {
     return labPart.name == req.partName;
   });
   if (labInfo.labParts.length == newLabParts.length) {
     return sendError('Lab part ' + req.partName + ' not found');
   }
   labdb.updateHomeLab(home.name, startLab, newLabParts, function(e) {
     if (e) return sendError('Failed to update home lab', e);
   });
   home.labs[startLab].labParts = newLabParts;
   updateHomeLabParts(startLab);
 });
Example #13
0
 removeJoiningParticipant: function(user, options) {
     var joining = this.get("joiningParticipants");
     if (_.findWhere(joining, {id: user.id})) {
         joining = _.reject(joining, function(u) { return u.id == user.id; });
         this.set({"joiningParticipants": joining}, options || {});
         if (!this.isDeleted()) {
             this.save();
         }
     }
     if (this.joiningTimeouts[user.id]) {
         clearTimeout(this.joiningTimeouts[user.id]);
         delete this.joiningTimeouts[user.id];
     }
 },
Example #14
0
 removeAdmin: function(user) {
     var admins = this.get("admins");
     admins = _.reject(admins, _.bind(function(admin) {
         if (this.adminMatchesUser(admin, user)) {
             changed = true;    
             return true;
         }
         return false;
     }, this));
     if (changed) {
         this.set("admins", admins);
         this.trigger("change:admins", this, admins);
         this.trigger("change", this);
     }
 },
Example #15
0
 remove: function(item) {
   if (!item) {
     return false;
   }
   var foundItem = false;
   this.items = _.reject(this.items, function(it) { 
     if (it === item) {
       foundItem = true;
       return true;
     }
     return false;
   });        
   delete this.itemCache[item[this.options.idKey]];
   if (foundItem) {
     this.fire("itemRemoved", item);
     if (this.items.length == 0) {
       this.fire("cleared");
     }
     return true;
   }
   return false;
 },
Example #16
0
    return num * 3;
}));

// reduce:集合元素合并到memo
console.log(_.reduce([1,2,3], function(memo, num){
    return memo + num
}, 0));

// filter: 过滤集合中符合条件的元素
console.log(_.filter([1,2,3,4,5,6], function(num){
    return num % 2 == 0;
}));

// reject: 过滤集合中不符合条件的元素
console.log(_.reject([1,2,3,4,5,6], function(num){
    return num % 2 == 0;
}));

// where: 遍历list, 返回新的对象数组
var list = [
    {title: 'aaa', year: 1982},
    {title: 'bbb', year: 1990},
    {title: 'ccc', year: 1982}
];
console.log(_.where(list, {year: 1982}));

// contains: 判断元素是否在list中
console.log(_.contains([1,2,3,4], 8));

// invoke: 在list里的每个元素上调用名为methodName的函数,任何附加的函数传入,invoke将会转给调用的函数
var v = _.invoke([[2,1,3], [4,5,2]], 'sort')
Example #17
0
 delete_client: function(client) {
     this.clients = _.reject(this.clients, function(){
         return this.clients === client;
     })
 }
Example #18
0
 _.each(o.orderTimes, ot=> {
     ot._doc.times = _.reject(ot.times, time=>time < _time);
     if (!_.isEmpty(ot.times) && !_.contains(ids, ot._id)) {
         orderTimes.push(ot);
     }
 });