Skip to content

Instantly share code, notes, and snippets.

View raycmorgan's full-sized avatar

Ray Morgan raycmorgan

  • Stripe
  • San Francisco, CA
View GitHub Profile
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);
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);
@raycmorgan
raycmorgan / async_ext.js
Created January 17, 2014 20:47
async.applyDeps
// ----------------------------------------------------------------------------
// Requirements
// ----------------------------------------------------------------------------
var _ = require('underscore')
, async = require('async');
// ----------------------------------------------------------------------------
// Public functions
// ----------------------------------------------------------------------------
var objOne = {};
var objTwo = {};
objOne.foo = {};
objOne.foo.bar = 100;
objTwo = objOne;
objTwo.foo.bar = 200;
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);
@raycmorgan
raycmorgan / gist:1636039
Created January 18, 2012 21:54 — forked from jimmyjacobson/gist:1631704
Redis Queries
=== database object file
var errors = require('./errors');
var db;
exports.setDatabase = function(database) {
db = database;
}
var foo = db.get('foo', function (err, res) {
callback(err, res);
});
contents = fs.readFile("/path/to/file.txt");
// do stuff with contents
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);
/*
* hookio/protocols/mustache
* Implements a mustache protocol for parsing mustache tags out of text
*/
var hookIO = require('../../hookio').hookIO,
mu = require('../lib/mu/lib/mu');
exports.start = function() {
// little test case