Skip to content

Instantly share code, notes, and snippets.

View gjohnson's full-sized avatar

Garrett Johnson gjohnson

View GitHub Profile
@gjohnson
gjohnson / condition.js
Created February 18, 2012 23:14
Backbone LayoutManager Stuff
var ConditionView = Backbone.View.extend({
template: '#ponder-view-condition',
initialize: function() {
_.bindAll(this, 'appendStatement');
this.model.get('children').on('add', this.appendStatement);
},
render: function(layout) {
@gjohnson
gjohnson / app.js
Created March 19, 2012 04:48
Reload config files.
var fs = require('fs')
, config = JSON.parse(fs.readFileSync('./config.json'));
setInterval(function() {
console.log('config.foo = %s', config.foo);
}, 500);
process.on('SIGHUP', function() {
fs.readFile('./config.json', function(err, contents) {
if (err) return console.error(err);
@gjohnson
gjohnson / test.parser.js
Created July 26, 2012 22:32
multipart parser
var assert = require('assert');
function pack(data, meta) {
var frames;
// an array of msgs means we want multipart
// frame each msg, then create an outer frame for the entire msg.
if (Array.isArray(data)) {
@gjohnson
gjohnson / test.encode.js
Created July 31, 2012 09:10
multipart messsages
var ss = require('..')
, encoder = new ss.Encoder
, decoder = new ss.Decoder
, should = require('should')
, msgs;
// capture messages
decoder.onmessage = function(body, multi) {
@gjohnson
gjohnson / kill-child.js
Created August 23, 2012 01:28
kill children example
function killChildren(callback){
var keys = Object.keys(processes)
, count = keys.length;
keys.forEach(function(pid){
var proc = processes[pid];
delete processes[pid];
proc.on('exit', function(){
if (--count === 0) callback();
@gjohnson
gjohnson / foo.js
Created August 23, 2012 02:18
emitter demo
// require events module, we only need the emitter so we grab it off pronto.
var EE = require('events').EventEmitter;
// define our constructor and call the "EE" constructor function, this gets scoping all happy for you (think call "super" in PHP).
function Foo(){
EE.call(this);
this.timer = null;
}
@gjohnson
gjohnson / product_pipeline.js
Created September 26, 2012 11:42
Product Stream
/**
* Deps.
*/
var express = require('express')
, es = require('event-stream')
, fs = require('fs')
, path = require('path');
@gjohnson
gjohnson / parser.js
Created September 30, 2012 19:07
memcache parser
var Parser = require('../lib/parser');
var parser = new Parser();
parser.onreply = console.log;
parser.write('ERR');
parser.write('O');
parser.write('R\r\n');
parser.write('CLIENT_');
@gjohnson
gjohnson / config.json
Created November 7, 2012 22:51
env aware config
{
"redis host": "localhost",
"redis port": 6379,
"fluent buffer": "/tmp/buffer"
}
@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();