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 async = require('async'); | |
function one(cb) { | |
console.log("running one"); | |
cb(null, function () { return "one" }); | |
} | |
function two(cb) { | |
console.log("running two"); | |
function three(callback){ |
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
#!/bin/bash | |
if [[ $1 != "-f" ]]; then | |
echo "### Dry-run mode, specify -f to actually perform deletes."; | |
fi; | |
for branch in $(git branch -r --merged origin/master | grep '\<origin/' | grep -v '\<origin/master\>'); | |
do | |
if [[ -z $(git rev-list $branch --since '1 month') ]]; then | |
name=$(echo $branch | sed 's/^origin\///'); | |
if [[ $1 = "-f" ]]; then |
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
// Short module explanation // Something to gather my thoughts | |
// // I think this looks cool. | |
// | |
module.exports = the_exported_function // Modules are a function. Always. | |
// | |
module.exports.extra = extra // Additional API entry points if | |
module.exports.other = other // desired. | |
// | |
var util = require('util') // Other packages from npm or core | |
var assert = require('assert') // No comma-first due to lots of |
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 cluster = require('cluster'); | |
var PORT = +process.env.PORT || 1337; | |
if (cluster.isMaster) { | |
// In real life, you'd probably use more than just 2 workers, | |
// and perhaps not put the master and worker in the same file. | |
cluster.fork(); | |
cluster.fork(); | |
cluster.on('disconnect', function(worker) { |
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 redis = require("redis") | |
undefined | |
> var c = redis.createClient() | |
undefined | |
> c.blpop("Dispo", 0, console.log) | |
true | |
> null [ 'Dispo', 'foo' ] |
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
fs.readFile('/proc/meminfo', 'utf8', function (err, str) { | |
var fields = {}; | |
str.split('\n').forEach(function (line) { | |
var parts = line.split(':'); | |
if (parts.length === 2) { | |
fields[parts[0]] = parts[1].trim().split(' ', 1)[0]; | |
} | |
}); | |
cb(fields['MemTotal'] + fields['Buffers'] + fields['Cached']); |
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 lvlup = require("levelup") | |
var db = lvlup("/tmp/source_db") | |
var batch = 10000 | |
function makeBatch(num) { | |
var b = [] | |
for (var i = num; i < num + batch; i++) { | |
b.push({type: "put", key: "z~" + i, value: Math.random()}) |
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 Transform = require("stream").Transform | |
var inherits = require("util").inherits | |
module.exports.ctor = function ctor(fn) { | |
function T(options) { | |
if (!(this instanceof T)) return new T(options) | |
Transform.call(this, options) | |
} | |
inherits(T, Transform) | |
T.prototype._transform = fn |
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
require("pipechain").install() | |
var spigot = require("stream-spigot") // or whatever you like to create streams | |
var s = spigot(["a", "b", "c", "\n"]) | |
+s | |
require("./other.js") | |
// console will read abc |
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
module.exports = align | |
var Transform = require("stream").Transform | |
|| require("readable-stream/transform") | |
var inherits = require("util").inherits | |
var map = require("through2-map") | |
/** | |
* align takes two objectMode streams and a sequence key and will create a stream | |
* aligning records from each stream resulting in a stream that emits record doublets |
OlderNewer