Skip to content

Instantly share code, notes, and snippets.

:atom:
Coding at yuque.com

fengmk2 fengmk2

:atom:
Coding at yuque.com
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
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 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('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 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 https://github.com/joyent/node/blob/v0.11.12/lib/http.js
@fengmk2
fengmk2 / node-gyp-windows.md
Last active Aug 29, 2015
node-gyp build deps on windows
View node-gyp-windows.md

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 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
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) {
View how-i-use-npm.md
  • 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 Aug 29, 2015
How cnpmjs.org work
View cnpm.puml
@startuml
node "cnpmjs.org Cluster" {
[cnpm registry]
[cnpm web]
[cnpm sync worker]
}
node "original npm Cluster" {
[npm registry]
@fengmk2
fengmk2 / totoro.puml
Last active Aug 29, 2015
How totoro work
View totoro.puml
@startuml
node "totoro users" {
[totoro cli]
}
node "browsers" {
[chrome]
[firefox]
[phantomjs]
You can’t perform that action at this time.