This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Stack | |
* LIFO data structure | |
*/ | |
exports.Stack = Stack; | |
exports.Stack1 = Stack1; | |
exports.Stack2 = Stack2; | |
exports.Stack3 = Stack3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"scripts": { | |
"test": "mocha -r should --recursive", | |
"test-watch": "mocha -r should --recursive -w -G -R min", | |
"coverage": "istanbul cover _mocha -- -r should --recursive" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http') | |
, url = require('url') | |
, path = require('path') | |
, fs = require('fs') | |
, HTTP_PORT = (process.env.PORT || 3000) | |
, server; | |
server = http.createServer(function (req, res) { | |
var publicDir = path.join(__dirname, 'public'); | |
serveStatic(publicDir, req, res); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//process.env.NODE_ENV = 'production' | |
var express = require('express') | |
, fs = require('fs') | |
, path = require('path') | |
, trumpet = require('trumpet') | |
, nap = require('nap') | |
, app = express() | |
nap({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {Array} list of middleware to combine | |
*/ | |
module.exports = function (list) { | |
return function (req, res, next) { | |
(function iter(i) { | |
var mid = list[i] | |
if (!mid) return next() | |
mid(req, res, function (err) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = Lib | |
function Lib() { | |
this._queue = [] | |
var methods = ['one', 'two', 'three'] | |
methods.forEach(this._addMethod.bind(this)) | |
} | |
Lib.prototype._addMethod = function (name) { | |
var self = this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncMap(sparseArr, factory, cb) { | |
var completed = [] | |
, sparseLen = sparseArr.length | |
, len = 0 | |
, ctr = 0 | |
, isDone = false | |
, item | |
, i; | |
function done(err, good) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function _git { | |
git --git-dir=$1/.git --work-tree=$1 $2 | |
} | |
function _git_pull { | |
_git $i fetch && \ | |
_git $i "merge origin/master" | grep -v "Already up-to-date." | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cluster = require('cluster'); | |
var http = require('http'); | |
var numCPUs = 3; | |
var workers = []; | |
if (cluster.isMaster) { | |
for (var i = 0; i < numCPUs; i++) { | |
workers.push(cluster.fork()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var page = require('./page'); | |
function getFullPage(id, cb) { | |
var combined = {id: id, modules: []}; | |
_get(id, combined, cb); | |
} | |
function _get(id, combined, cb) { | |
function onGet(err, page) { | |
if (err) return cb(err); |