Skip to content

Instantly share code, notes, and snippets.

View edwardhotchkiss's full-sized avatar

Edward Hotchkiss edwardhotchkiss

View GitHub Profile
@edwardhotchkiss
edwardhotchkiss / node-sinatra.js
Created January 3, 2012 21:23
NodeJS minimal `sintra` style router
/**
* Node.JS Sinatra Style Routing
*/
var routes = {}
, http = require('http')
, parse = require('url').parse
, server = http.createServer();
/**
/**
* Uses MongooseJS to Connect to MongoDB
* .Maps out all collections within
*/
var mongoose = require('mongoose')
, MONGO_DB = 'mongodb://localhost/test';
mongoose.connect(MONGO_DB);
@edwardhotchkiss
edwardhotchkiss / colors.js
Created December 22, 2011 19:55
NodeJS CLI Terminal Colors
/*!
__defineGetter__(<ANSI supported color>, fn
http://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes
*/
['magenta','yellow','green','blue','cyan','red'].forEach(function(color) {
var colorized = '\u001b[#m';
String.prototype.__defineGetter__(color, function(){
var options = {
@edwardhotchkiss
edwardhotchkiss / spawn.test.js
Created December 10, 2011 14:52
Testing a NodeJS spawned process (.spawn) with Vows BDD Test Suite
var child
, stdout = ''
, stderr = ''
, exitCode = 0
, vows = require('vows')
, path = require('path')
, assert = require('assert')
, request = require('request')
, spawn = require('child_process').spawn;