Skip to content

Instantly share code, notes, and snippets.

Ray Morgan raycmorgan

  • Stripe
  • San Francisco, CA
View GitHub Profile
View queryMatch.js
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);
View rj.js
var rj = require('rj');
// item.js
exports['1.2.0'] = {
$defaultFields: ['id', 'live', 'createdAt', 'owner'],
$select: [{_id: 'id'}, 'live'],
View async_ext.js
// ----------------------------------------------------------------------------
// Requirements
// ----------------------------------------------------------------------------
var _ = require('underscore')
, async = require('async');
// ----------------------------------------------------------------------------
// Public functions
// ----------------------------------------------------------------------------
View gist:2347104
var objOne = {};
var objTwo = {};
objOne.foo = {};
objOne.foo.bar = 100;
objTwo = objOne;
objTwo.foo.bar = 200;
View gist:1636123
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);
View gist:1636039
=== database object file
var errors = require('./errors');
var db;
exports.setDatabase = function(database) {
db = database;
}
View gist:1573599
var foo = db.get('foo', function (err, res) {
callback(err, res);
});
View gist:1512302
contents = fs.readFile("/path/to/file.txt");
// do stuff with contents
View murmurhash2.js
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);
View gist:588421
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);
You can’t perform that action at this time.