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
// Takes any async lib that uses callback based signatures and converts | |
// the specified names to continuable style and returns the new library. | |
exports.convert = function (lib, names) { | |
var newlib = {}; | |
Object.keys(lib).forEach(function (key) { | |
if (names.indexOf(key) < 0) { | |
return newlib[key] = lib[key]; | |
} | |
newlib[key] = function () { | |
var args = Array.prototype.slice.call(arguments); |
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 crypto = require('crypto'); | |
/** | |
* Calculates the hash/checksum of a string. Default algorithm is MD5. | |
* | |
* @param {String} str | |
* @param {String} algorithm | |
* @return {String} checksum | |
* @api public | |
*/ |
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
Array.prototype.asyncEach = function(iterator) { | |
var list = this, | |
n = list.length, | |
i = -1, | |
calls = 0, | |
looping = false; | |
var iterate = function() { | |
calls -= 1; | |
i += 1; |
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
// Use built in or binary modules | |
var crypto = require('crypto'); | |
var hash = crypto.createHmac("sha1",key).update(signatureBase).digest("base64"); |
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(A) { | |
var registered_ids = {}, | |
id_to_module_map = {}, | |
interim_actions = {}, | |
cleanup_actions = {}, | |
clicked_ids = {}, | |
queueing = {}; | |
function register_id(id, callbacks, required_module) { | |
id = id.replace('*', '.*'); |
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
c_cyan="\033[36m" | |
c_red="\033[31m" | |
c_green="\033[32m" | |
c_pink="\033[35m" | |
c_sgr0="\033[0m" | |
parse_branch () | |
{ | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then |
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 p = require('./point'); | |
> var o = new p.Point(); | |
> o.setX(6); | |
> o.setY(9); | |
> console.log(o.get()); | |
{ x: 6, y: 9 } |
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 startFast; | |
var startSlow; | |
var size = 1000000; // million | |
var loopCount = 0; | |
var setTimeoutTest = function () { | |
loopCount++; | |
if ( loopCount == ( size - 1 ) ) { | |
console.log( 'setTimeout result: ' + ( new Date() - startFast ) + 'ms' ); |
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 (ctr,t) { | |
function inc () { ctr++ } | |
function display (ntps,ntpsStr,i,lps,lpsStr,ratioStr) { | |
ntps= ctr*1e3/(Date.now()-t); //nextTicks per second | |
ntpsStr= ", nextTicksPerSecond: "+ ntps.toFixed(1); | |
ctr= 0, i= 100e6, t= Date.now(); | |
while (i--) { inc() } |
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 express = require('express'); | |
var redis = require('redis'); | |
const serverType = process.argv[2]; | |
const serverHost = process.argv[3]; | |
const serverPort = parseInt(process.argv[4]); | |
const redisPort = 6379; | |
const redisHost = '127.0.0.1'; |