Skip to content

Instantly share code, notes, and snippets.

View gjohnson's full-sized avatar

Garrett Johnson gjohnson

View GitHub Profile
@gjohnson
gjohnson / index.html
Created March 9, 2013 22:39
multiply video via canvas
<!DOCTYPE html>
<html>
<head>
<title>video - wall</title>
<style>
body {
padding: 0;
margin: 0;
}
@gjohnson
gjohnson / pad-hacking.js
Created February 16, 2013 00:02
padding hack
var padding = {
'128': pad(128),
'512': pad(512)
};
collection.insert({
aliases: [ padding['128'] ],
profile: { 'noop': padding['512'] },
}, function(err, doc){
var query = { _id: doc._id };
@gjohnson
gjohnson / interface.md
Created January 23, 2013 06:44
mquery collection interface

Collection

  • insert
  • remove
  • rename
  • save
  • update
  • distinct
  • count
  • drop
@gjohnson
gjohnson / app.js
Created January 2, 2013 18:42
express verbose logging
express.logger.format('verbose', ''
+ ':date - '
+ ':remote-addr - '
+ ':user-agent -- '
+ ':method - '
+ ':url - '
+ ':status -- '
+ ':req[dnt] - '
+ ':req[x-do-not-track] - '
+ ':req[x-forwarded-for] - '
@gjohnson
gjohnson / to-args.js
Created December 29, 2012 22:25
booh!
var assert = require('assert')
, result;
function toArgs(val){
if (Array.isArray(val[0])) return val[0];
var len = val.length;
var ret = new Array(len);
for (var i = 0; i < len; ++i) {
ret[i] = val[i];
}
@gjohnson
gjohnson / example.js
Created December 20, 2012 22:33
mongoose revision plugin
var mongoose = require('mongoose')
, revision = require('..')
, Schema = mongoose.Schema;
mongoose.connect('localhost', 'sandbox');
var schema = new Schema({
title: String,
content: String
});
@gjohnson
gjohnson / bitcrunch.js
Created December 15, 2012 20:06
ideas for the api
// http://amix.dk/blog/post/19714#bitmapist-Powerful-realtime-analytics-with-Redis-2-6s-bitmaps-and
var bitcrunch = require('bitcrunch')
, client = bitcrunch.connect();
// mark user 123 as active and has played a song:
client.mark('active', 123, fn);
client.mark('song:played', 123, fn);
@gjohnson
gjohnson / test.js
Created November 18, 2012 22:47
constraints
var constraint = require('constraint');
var assert = require('assert');
// create engine
var engine = constraint()
.contains('whatever', 'red')
.equals('some.thing.really.nested', 'works');
// need a custom rule?
@gjohnson
gjohnson / batch.js
Created November 15, 2012 22:33
stream processing large csv
/**
* Deps.
*/
var redis = require('redis')
, fs = require('fs')
, csv = require('csv')
, rc = redis.createClient();
@gjohnson
gjohnson / config.json
Created November 7, 2012 22:51
env aware config
{
"redis host": "localhost",
"redis port": 6379,
"fluent buffer": "/tmp/buffer"
}