Skip to content

Instantly share code, notes, and snippets.

View dead-horse's full-sized avatar
🤖
I may be slow to respond.

Yiyu He dead-horse

🤖
I may be slow to respond.
View GitHub Profile
@dead-horse
dead-horse / http_keepalive_async.js
Last active August 29, 2015 14:05
pipe bug in node 0.10.30
var http = require('http');
var fs = require('fs');
var path = require('path');
var tmp = path.join(__dirname, 't.tgz');
var opts = {
hostname: 'registry.npmjs.com',
method: 'GET',
port: 80,
path: '/cutter/-/cutter-0.0.3.tgz',
@dead-horse
dead-horse / bench.js
Created August 23, 2014 16:20
co benchmark for thunk and promise
var benchmarks = require('beautify-benchmark');
var Benchmark = require('benchmark');
var thunkify = require('thunkify');
var zlib = require('zlib');
var co = require('co');
var fs = require('fs');
var gzipPromise = require('mz/zlib').gzip;
var gzipThunk = thunkify(zlib.gzip);
var fsPromise = require('mz/fs');
var path = require('path');
var simplePath = '/home/Users/deadhorse/git/node/lib/path.js';
var pathWithDot = '/home/Users/deadhorse/git/node/./lib/./path.js';
var pathWithDotDot = '/home/Users/deadhorse/git/node/../lib/../path.js';
var length = 1000000;
console.time('normalize simple path');
for (var i = 0; i < length; i++) {
function test(path) {
return path.split('/').join('/');
}
var path1 = 'first';
var path2 = 'second';
var longPath = '.././home//Users/name/git/project/lib/abc/def/zzz.js';
var plusPath = path1 + '/' + path2 + '/' + longPath;
var constantPath = 'first/second/.././home//Users/name/git/project/lib/abc/def/zzz.js';
var cp = require('child_process');
var urllib = require('urllib');
exports.ipMap = {};
var urls = [
'www.baidu.com',
'www.tmall.com'
];
00:00
beats: http://miao.item.taobao.com/41781815440.htm?mt=&spm=a1z0k.7385961.1997985097.d4918997.eNalBC&_u=ab1pr6m5afb
mk: http://detail.tmall.hk/hk/item.htm?id=41848825576
00:30
tcl: http://miao.item.taobao.com/35246887163.htm?mt=
01:00
表: http://miao.item.taobao.com/41827050867.htm?mt=
function Cube() {
this.commands = [];
}
Cube.prototype.executeCommand = function (commands, callback) {
this.commands = commands;
this.commandCallback = callback;
this._execute();
};
(function (exports) {
//---------------------------------------------------------------
//------------------------set up editor--------------------------
//---------------------------------------------------------------
var editor1 = ace.edit("editor1");
editor1.setTheme("ace/theme/monokai");
editor1.getSession().setMode("ace/mode/javascript");
var editor2 = ace.edit("editor2");
editor2.setTheme("ace/theme/monokai");
editor2.getSession().setMode("ace/mode/javascript");
// error in next tick
try {
setImmediate(function () {
throw new Error('error happened');
});
} catch (err) {
// 捕获不到异常
}
// get json by callback