Skip to content

Instantly share code, notes, and snippets.

View fengmk2's full-sized avatar
:atom:
Coding at antgroup.com

fengmk2 fengmk2

:atom:
Coding at antgroup.com
View GitHub Profile
describe('index.test.js', function () {
it('should work with co', function *() {
yield *foo();
yield bar();
});
});
root@net4app1:/var/log/nginx# cat access.log.1 |awk '{print $1}'|sort -nr |uniq -c |sort -nr |head -n 10
175721 119.254.241.70
53685 61.182.139.0
31610 66.249.75.92
26467 66.249.73.222
24021 211.151.229.229
23930 211.151.229.248
23918 211.151.229.231
23869 211.151.229.246
23836 211.151.229.247
@fengmk2
fengmk2 / co-mocha.js
Created March 13, 2014 01:45
co very nice to mocha
describe('example of co work with mocha', function () {
it('should work', co(function *() {
var result = yield *urllib.request('http://cnpmjs.org', {dataType: 'json'});
result.should.have.keys('data', 'status', 'headers');
result.status.should.equal(200);
result.data.should.be.an.Object;
result.headers['content-type'].should.equal('application/json');
}));
});
@fengmk2
fengmk2 / deprecate.js
Created March 14, 2014 01:23
deprecate an old api
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 https://github.com/joyent/node/blob/v0.11.12/lib/http.js
@fengmk2
fengmk2 / node-gyp-windows.md
Last active August 29, 2015 13:57
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
fengmk2 / http_aborted.js
Created April 11, 2014 09:28
make http res aborted event emit.
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
fengmk2 / master.js
Last active August 29, 2015 14:01
cluster dir watcher
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) {
@fengmk2
fengmk2 / how-i-use-npm.md
Created June 15, 2014 15:26
How I use npm
  • 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
fengmk2 / cnpm.puml
Last active August 29, 2015 14:03
How cnpmjs.org work
@startuml
node "cnpmjs.org Cluster" {
[cnpm registry]
[cnpm web]
[cnpm sync worker]
}
node "original npm Cluster" {
[npm registry]
@fengmk2
fengmk2 / totoro.puml
Last active August 29, 2015 14:03
How totoro work
@startuml
node "totoro users" {
[totoro cli]
}
node "browsers" {
[chrome]
[firefox]
[phantomjs]