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 Benchmark = require('benchmark'); | |
var suite = new Benchmark.Suite; | |
var dataString = ['xxx', 'ssss', 'yyyyy', '1121212', 'aaaaa']; | |
var dataBuffer = [new Buffer('xxx'), new Buffer('ssss'), new Buffer('yyyyy'), new Buffer('1121212'), new Buffer('aaaaa')]; | |
suite.add('Buffer#copy', function() { | |
var offset = 0; | |
dataBuffer.forEach(function(chunk) { |
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
/* Kosso : March 12th 2011 | |
This the only way I managed to do this without the app crashing on resume. | |
Done slightly differently to the KS example, since they unregister the service and | |
do not use a setInterval timer. | |
*/ | |
//############ in app.js : | |
// test for iOS 4+ |
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 mongodbSrc = require('./mongodb-0.9.4-3'); | |
var mongodbDst = require('./mongodb-0.9.6-1'); | |
/**** Edit start ****/ | |
var SRC_HOST = '10.0.0.31'; | |
var SRC_PORT = 27017; | |
var SRC_DB_NAME = 'mydb'; | |
var SRC_ROOT_COLLECTION = 'images'; | |
var FILE_QUERY = {}; // default to all |
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
// RegExp copied from sina weibo;) | |
function makeReFn(regStr) { | |
var re = typeof regStr == 'string' ? new RegExp(regStr) : regStr; | |
return function (beRegStr) { | |
if (re.test(beRegStr)) { | |
return true; | |
} else { | |
return false; | |
} |
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 CreateHash = require('crypto').createHash, | |
StringDecoder = require('string_decoder').StringDecoder, | |
Bisection = require('./utils').Bisection; | |
/* | |
example usage: | |
var sys = require( 'sys' ), | |
hashing = require( '../lib/hashring' ), | |
hashring = new hashing.hashRing( | |
[ '192.168.0.102:11212', '192.168.0.103:11212', '192.168.0.104:11212' ], |
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 c = require('crypto'); | |
// cipher to binary | |
var cipher = c.createCipher('aes192', 'hello'); | |
var en = cipher.update('你好你好你好你好你好dfferfdgwefdv4t5g56euhergy56yhe54wtfgq34tg你好你好你好你好你好你好你好erwgw43etr', 'utf8', 'binary') + cipher.final('binary'); | |
console.log(en); | |
// binary to base64 | |
var buff = new Buffer(en, 'binary'); | |
var base64 = buff.toString('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() { | |
var me = this, | |
writeHead = me.flaker.writeHead, | |
write = me.flaker.write, | |
contentType = mime.lookup(extname(filePath)); | |
fs.stat(filePath, function(err, stat) { | |
if (err || !stat.isFile()) { | |
errback ? errback(err) : me.error(404, 'File not found'); | |
return; | |
} |
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 Pool = Base(EventEmitter, { | |
init: function(getConnection, size) { | |
this._super(); | |
this._pool = []; | |
this._queue = []; | |
this.size = size; | |
var me = this; | |
getConnection(size, function(conn) { | |
me.emit('back', conn); | |
}); |
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 strict'; | |
module.exports = { | |
re: function(fnName, context) { | |
var fn; | |
context = context || this; | |
if ('function' === typeof fnName) { | |
fn = fnName; | |
fnName = fn.toString().match(/^\s*function\s*(\S*)\s*\(/)[1]; | |
} else { |