Skip to content

Instantly share code, notes, and snippets.

View indexzero's full-sized avatar
🌎
Always bet on Open Source

Charlie Robbins indexzero

🌎
Always bet on Open Source
View GitHub Profile
@indexzero
indexzero / analysis.md
Created June 21, 2011 00:20
An analysis of the data structures used in EventEmitter2 (http://github.com/hij1nx/eventemitter2)

Previously events had been stored in an n-ary tree of arbitrary depth (i.e. a deep Javascript object literal), the nodes of which are individual values of a split event. e.g.

var emitter = new EventEmitter2({ delimiter: ':' });
emitter.on('foo:bar:*', function () { });
emitter.on('foo:foo:foo', function () { });
emitter.on('bazz:buzz:foo', function () { });
emitter.on('bazz:fizz:tar', function () { });
@indexzero
indexzero / seq-async-vows.js
Created June 21, 2011 23:32
A quick tutorial of sequential async testing in vows
var vows = require('vows'),
assert = require('assert'),
fs = require('fs');
var first;
vows.describe('some/file/testing').addBatch({
"First we want to read a file": {
topic: function () {
first = true;
@indexzero
indexzero / mock-request-usage.js
Created June 22, 2011 00:25
A quick and dirty example of some APIs that could go into a "mock-request" library
var mockRequest = require('mock-request');
console.dir(mockRequest
.get('/auth').responds(200)
.get('/apps/mickey').responds(200, { /* some JSON */ }));
// [
// {
// request: {
// //
@indexzero
indexzero / helpers.js
Created June 22, 2011 03:05
A quick sample of how to use api-easy with `npm test`
/*
* helpers.js: Test macros for APIeasy.
*
* (C) 2011, Charlie Robbins
*
*/
var assert = require('assert'),
http = require('http'),
journey = require('journey');
@indexzero
indexzero / gist:1076657
Created July 11, 2011 19:55 — forked from bmeck/gist:1076655
Http over domain socket
bradley@macaroon:~$ cat Documents/issues/ping_domain_socket.js
var socket = './'+process.argv[2];
var http = require('http');
var req = http.request({
socketPath:socket,
path:'/',
method:'POST'
})
setInterval(function(){req.write(process.argv[3])},1000)
@indexzero
indexzero / demo.js
Created July 12, 2011 20:30 — forked from sorensen/demo.js
Raphael icon factory
// Basic usage
_.icon('home', 'home-id-selector')
// Advanced usage
_.icon('power', 'start-menu-icon', {
fill : {
fill : "#333",
stroke : "none"
},
none : {
var vows = require('vows'),
assert = require('assert');
function wait(callback) {
setTimeout(function() {
callback('hello', 'world');
}, 2000)
}
@indexzero
indexzero / gist:1114798
Created July 29, 2011 21:39
~ and ~~ in Arrays
var x = [1,2,3,4,5],
y = ['a', 'b', 'c', 'd', 'e'];
// console.log(x.indexOf(6)); // -1
// console.log(x.indexOf(5)); // 4
//
// if(x.indexOf(6) === - 1) { // if -1 === -1
// console.log(true, 'x.indexOf(6) === - 1');
// }
//
@indexzero
indexzero / some-resource.js
Created August 1, 2011 06:43
An example of a possible "resource" API in node.js
var util = require('util'),
resourceLib = require('our-new-resource-lib');
var SomeResource = function (options) {
resourceLib.Resource.call(this, options);
//
// Setup any other application specific state.
//
@indexzero
indexzero / README.markdown
Created August 3, 2011 10:07
EventEmitter2 digs DIRT and ETL applications.

require('child_process').fork() and beyond

Abstract

The purpose of this sample is to show the power of EventEmitter2 in the context of a specific example centered around [DIRT][0] (Data-Intensive Realtime) and [ETL][0] (Extract, Transform, Load) applications in node.js. Given the clear limitations of the V8 heap-size doing any exceptionally large data processing in node will require such patterns, and it is in the interest of the community that we start solidifying them.

Scenario

Lets suppose that you have an ETL that you need to run on a large set of logs which has already been partitioned into files of a size that will by themselves not overload the V8 heap. These kind of size-limited log or data files are common and should need no explaination.

This ETL runs with initial conditions (very common), and thus there may be many sets of worker processes analyzing the same data for different purposes. As an intelligent developer knowning the blocking nature of in-memory data manipulation you decided