This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function queryMatch(obj, query) { | |
| return _.every(query, function (pred, key) { | |
| if (_.contains(['$and', '$or', '$nor'], key)) { | |
| assert(Array.isArray(pred), 'Value of ' + key + ' must be an array'); | |
| var recur = _.partial(queryMatch, obj); | |
| switch (key) { | |
| case '$and': return _.every(pred, recur); | |
| case '$or': return _.some(pred, recur); | |
| case '$nor': return !_.some(pred, recur); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var rj = require('rj'); | |
| // item.js | |
| exports['1.2.0'] = { | |
| $defaultFields: ['id', 'live', 'createdAt', 'owner'], | |
| $select: [{_id: 'id'}, 'live'], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ---------------------------------------------------------------------------- | |
| // Requirements | |
| // ---------------------------------------------------------------------------- | |
| var _ = require('underscore') | |
| , async = require('async'); | |
| // ---------------------------------------------------------------------------- | |
| // Public functions | |
| // ---------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var objOne = {}; | |
| var objTwo = {}; | |
| objOne.foo = {}; | |
| objOne.foo.bar = 100; | |
| objTwo = objOne; | |
| objTwo.foo.bar = 200; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function foo(key, callback) { | |
| db.get(key, function (err, result) { | |
| callback(err, result); | |
| }) | |
| } | |
| // is the same as: | |
| function foo(key, callback) { | |
| db.get(key, callback); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| === database object file | |
| var errors = require('./errors'); | |
| var db; | |
| exports.setDatabase = function(database) { | |
| db = database; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var foo = db.get('foo', function (err, res) { | |
| callback(err, res); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| contents = fs.readFile("/path/to/file.txt"); | |
| // do stuff with contents |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function doHash(str, seed) { | |
| var m = 0x5bd1e995; | |
| var r = 24; | |
| var h = seed ^ str.length; | |
| var length = str.length; | |
| var currentIndex = 0; | |
| while (length >= 4) { | |
| var k = UInt32(str, currentIndex); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function doHash(str, seed) { | |
| var m = 0x5bd1e995; | |
| var r = 24; | |
| var h = Math.pow(seed, str.len); | |
| var length = str.length; | |
| var currentIndex = 0; | |
| while (length >= 4) { | |
| var k = UInt32(str, currentIndex); | |
NewerOlder