Skip to content

Instantly share code, notes, and snippets.

@nanha
nanha / gist:1308185
Created October 24, 2011 01:33 — forked from rogerdudler/gist:1156361
redis usage in node.js
// load redis client
var r = require('redis').createClient();
// set data for key
r.set('key', data);
// add data to key (list)
r.lpush('key', data);
// trim list to specific length
@nanha
nanha / gist:1385106
Created November 22, 2011 07:28
node.js CRC32
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
*/
@nanha
nanha / BinaryModules.js
Created December 6, 2011 00:23 — forked from brikis98/BinaryModules.js
Node.js performance tips
// Use built in or binary modules
var crypto = require('crypto');
var hash = crypto.createHmac("sha1",key).update(signatureBase).digest("base64");
@nanha
nanha / actionQueue.js
Created December 13, 2011 02:03 — forked from voidfiles/actionQueue.js
actionQueue
(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('*', '.*');
@nanha
nanha / node console
Created January 25, 2012 13:02 — forked from benmonty/node console
simple node.js v8 example
> var p = require('./point');
> var o = new p.Point();
> o.setX(6);
> o.setY(9);
> console.log(o.get());
{ x: 6, y: 9 }
@nanha
nanha / b2.js
Created January 27, 2012 07:55
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' );
@nanha
nanha / nextTick.js
Created January 27, 2012 07:58 — forked from xk/nextTick.js
nextTick.js
(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() }
@nanha
nanha / application.js
Created January 27, 2012 13:03 — forked from fabware/application.js
socket.io application and haproxy configuration
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';