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
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Updated: 2010/12/05
// License: MIT
//
// Copyright (c) 2010-2013 Diego Perini (http://www.iport.it)
//
// Permission is hereby granted, free of charge, to any person
@fengmk2
fengmk2 / http-errors-bench.js
Last active August 29, 2015 14:13
http-errors benchmark
var createError = require('http-errors');
var start = Date.now();
var count = 100000;
for (var i = 0; i < count; i++) {
createError(401, 'Please login to view this page.', {
stat: 'foo error',
errors: [
{
foo: 'bar',
@fengmk2
fengmk2 / vpnup-aws.sh
Created December 29, 2014 10:53
小米 vpn 翻墙自动路由记录
# for instagram, Amazon EC2
# https://forums.aws.amazon.com/ann.jspa?annID=1701
# US East (Northern Virginia):
route add -net 72.44.32.0/19 gw $VPNGW
route add -net 67.202.0.0/18 gw $VPNGW
route add -net 75.101.128.0/17 gw $VPNGW
route add -net 174.129.0.0/16 gw $VPNGW
route add -net 204.236.192.0/18 gw $VPNGW
route add -net 184.73.0.0/16 gw $VPNGW
route add -net 184.72.128.0/17 gw $VPNGW
@fengmk2
fengmk2 / oss.js
Created September 19, 2014 07:22
var ots = require('ots');
var client = ots.createClient({
accessID: 'your accessID',
accessKey: 'your accessKey'
});
// create a table
client.createTable({
TableName: 'testdemo',
PrimaryKey: [
@fengmk2
fengmk2 / agenthttps.js
Created August 28, 2014 11:07
agent https keepalive
/*!
* agentkeepalive - test/https_agent.test.js
*
* Copyright(c) 2012 - 2013 fengmk2 <fengmk2@gmail.com>
* MIT Licensed
*/
"use strict";
/**
@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]
@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 / 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 / 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 / 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);