Skip to content

Instantly share code, notes, and snippets.

Coding at

fengmk2 fengmk2

Coding at
Block or report user

Report or block fengmk2

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View co-mocha.js
describe('index.test.js', function () {
it('should work with co', function *() {
yield *foo();
yield bar();
View gist:9499852
root@net4app1:/var/log/nginx# cat access.log.1 |awk '{print $1}'|sort -nr |uniq -c |sort -nr |head -n 10
fengmk2 / co-mocha.js
Created Mar 13, 2014
co very nice to mocha
View co-mocha.js
describe('example of co work with mocha', function () {
it('should work', co(function *() {
var result = yield *urllib.request('', {dataType: 'json'});
result.should.have.keys('data', 'status', 'headers');
fengmk2 / deprecate.js
Created Mar 14, 2014
deprecate an old api
View deprecate.js
exports.Client = util.deprecate(Client,
'http.Client will be removed soon. Do not use it.');
exports.createClient = util.deprecate(function(port, host) {
return new Client(port, host);
}, 'http.createClient is deprecated. Use `http.request` instead.');
// from
fengmk2 /
Last active Aug 29, 2015
node-gyp build deps on windows

using node-gyp building nodejs c++ module on windows

Python (v2.7.3 recommended, v3.x.x is not supported)

Windows XP/Vista/7

  • Visual Studio 2010 Express, only need to install c++ tools
  • For 64-bit builds of node and native modules you will also need the Windows 7 64-bit SDK If the install fails, try uninstalling any C++ 2010 x64&x86 Redistributable that you have installed first.
  • If you get errors that the 64-bit compilers are not installed you may also need the compiler update for the Windows SDK 7.1
fengmk2 / http_aborted.js
Created Apr 11, 2014
make http res aborted event emit.
View http_aborted.js
var http = require('http');
var fs = require('fs');
var path = '/tmp/a.tgz';
var l = 0;
function request() {
var index = l++;
var stream = fs.createWriteStream(path);
fengmk2 / master.js
Last active Aug 29, 2015
cluster dir watcher
View master.js
var cluster = require('cluster');
function watchdir(dir) {
var watcher = childprocess.fork('watcher.js', [dir]);
watcher.on('exit', function () {
// logger exit message
watcher = null;
// refork again
setTimeout(watchdir.bind(null, dir), 1000);
}).on('message', function (info) {
  • day: private module, private npm

  • night: public module, public npm

  • company private project, use both public and private modules, install them from private npm registry

  • open source project, use only public modules, install them from public npm registry

  • private npm registry auto full sync public registry in 10 mins

  • When I publish a module to public registry, and I will use git hook to do the publish and sync actions:

$ git release 0.1.0
fengmk2 / cnpm.puml
Last active Aug 29, 2015
How work
View cnpm.puml
node " Cluster" {
[cnpm registry]
[cnpm web]
[cnpm sync worker]
node "original npm Cluster" {
[npm registry]
fengmk2 / totoro.puml
Last active Aug 29, 2015
How totoro work
View totoro.puml
node "totoro users" {
[totoro cli]
node "browsers" {
You can’t perform that action at this time.