This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * A simple co | |
| * @param {Function} fn Generator Function | |
| * @return {Function} callback | |
| */ | |
| function co(fn) { | |
| return function(done) { | |
| done = done || function() {}; | |
| var gen = fn(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Allow other processes to execute while iterating over | |
| * an array. Useful for large arrays, or long-running processing | |
| * | |
| * @param {Function} fn iterator fed each element of the array. | |
| * @param {Function} next executed when done | |
| */ | |
| Array.prototype.nonBlockingForEach = function(fn, next) { | |
| var arr = this; | |
| var i = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "os" | |
| "os/exec" | |
| "strings" | |
| "time" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 1. Make sure you have nginx sub module compiled in | |
| # nginx -V 2>&1 | grep --color=always '\-\-with\-http_sub_module' | |
| # 2. add two directives below at HTTP level | |
| # nginx.conf | |
| http { | |
| # ...... | |
| sub_filter '</head>' '<style type="text/css">html{ filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); -webkit-filter: grayscale(100%); filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var callA = function (callback) { | |
| setTimeout(function () { | |
| callback({name: "a", data: "I am result A"}); | |
| }, Math.round(Math.random() * 300)); | |
| }; | |
| var callB = function (callback) { | |
| setTimeout(function () { | |
| callback({name: "b", data: Math.round(Math.random() * 300)) % 2 === 0}); | |
| }, Math.round(Math.random() * 300)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //author: Sun, Junyi (weibo.com/treapdb) | |
| //usage: node --nouse-idle-notification --expose-gc --max-old-space-size=8192 memcached.js | |
| var config ={ | |
| port: 11211, | |
| max_memory: 100 // default 100M bytes | |
| } | |
| var net = require('net'); | |
| var LRU = function (max) { // this LRU implementaion is based on https://github.com/chriso/lru |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Load the TCP Library | |
| net = require('net'); | |
| // Keep track of the chat clients | |
| var clients = []; | |
| // Start a TCP Server | |
| net.createServer(function (socket) { | |
| // Identify this client |