- this
- is
- a
This file contains 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
Array.prototype.asyncMap = function (fn, callback) { | |
var that = this, i, count = 0, errors = [], map = []; | |
for (i = 0; i < this.length; i += 1) { | |
(function iter(i) { | |
fn(that[i], function (err, value) { | |
err && errors.push(err); | |
map[i] = value; | |
count += 1; | |
if (count === that.length) { | |
callback(errors.length ? errors : false, map); |
This file contains 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
<?php | |
$memcache = new Memcache; | |
$memcache->connect("localhost", 11211); | |
$memcache->flush(); | |
$list = array(); | |
$allSlabs = $memcache->getExtendedStats('slabs'); | |
$items = $memcache->getExtendedStats('items'); | |
foreach($allSlabs as $server => $slabs) { | |
foreach($slabs AS $slabId => $slabMeta) { |
This file contains 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 db = { | |
get: function (key, callback) { | |
setTimeout(function () { | |
callback(false, 'got ' + key); | |
}, Math.floor(Math.random() * 1000)); | |
} | |
}, | |
helpers = require('./2_helpers'); | |
// Here is a similar blocking example of what the following algorithms are doing: |
-
Blocking IO
+--------------------+--------------------+-----+ | read | write | md5 | +--------------------+--------------------+-----+
-
Asynchronous IO
+--------------------+
Bad:
{{gist bad_inheritance.js}}
Good:
{{gist inheritance.js}}
This file contains 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
NAME = 'BASE' | |
def get_name(): | |
return NAME |
This file contains 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 fs = require('fs'), | |
http = require('http'), | |
path = require('path'); | |
var CACHE_DIR = '.kitten_cache'; | |
if (!path.existsSync(CACHE_DIR)) { | |
fs.mkdirSync('.kitten_cache', 0755); | |
} else if (!fs.statSync(CACHE_DIR).isDirectory()) { | |
console.error('Cache dir `%s` must be a directory.', CACHE_DIR) |
This file contains 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
function seriesCoarse(first, second, interval, obj) { | |
var start = (new Date()).getTime(); | |
interval = interval || 1000; | |
obj = obj || this; | |
first.call(obj, function () { | |
setTimeout(function () { | |
}, interval - ((new Date()).getTime() - start) % interval); | |
}); |
OlderNewer