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 child_process = require('child_process'), | |
assert = require('assert') | |
var isChild = !!(process.send), | |
isMaster = ((!isChild) && (process.argv.length > 2)), | |
isTopLevel = (!isMaster && !isChild) | |
if( isTopLevel ) { |
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 | |
while true ; do | |
# there is no way to distinguish node's (1) exit code on SIGINT (and SIGTERM) | |
# from a (1) exit code due to normal exit call in userland. | |
# if node preserved SIGINT/SIGTERM, then the shell would detect node's | |
# "abnormal exit" status, and the script would terminate immediately after | |
# node returns | |
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 node(name) { | |
if (node.all[name]) { return node.all[name]; } | |
if (!(this instanceof node)) { return new node(name); } | |
node.all[name] = this; | |
this.name = name; | |
this.links = []; | |
this.toString = function() { return name; } | |
} | |
node.all = {}; |
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
/** | |
* examines the call stack (if available) and returns a string | |
* indicating the file and line number of the n'th previous ancestor call. | |
* this works in chrome, and should work in nodejs as well. | |
* | |
* @param n : int (default: n=1) - the number of calls to trace up the | |
* stack from the current call. `n=0` gives you your current file/line. | |
* `n=1` gives the file/line that called you. | |
*/ |
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/sh | |
# reliable path to current script in one-liner (handles spaces) | |
scriptpath=$(l=$(which "$0"); while :; do cd "$(dirname "$l")"; p=$(basename "$l"); \ | |
l=$(readlink "$p") || break; done; echo $(pwd)/$p) | |
echo \'$scriptpath\' |
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
const rxTemplateSubst = /\\?\${([^}]*)}/g; | |
function template(str, substitutions) { | |
if(!str) return str; | |
return str.replace(rxTemplateSubst, (token, name) => { | |
if(token[0] === '\\') return token.substr(1); | |
return String(substitutions[name]); | |
}); | |
} | |
// simple replacements... |
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
# usage: | |
# withnode <cmd> [<args>...] | |
# | |
# Invokes <cmd> after adjusting PATH to include the appropriate local node/bin | |
# directory. `node/bin` is first located by searching up the directory tree | |
# starting with the current working directory. | |
# | |
function withnode() { | |
path=$(pwd) | |
while [[ $path != '/' ]]; do |
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 | |
set -Eeuo pipefail | |
# for debug... | |
#set -x |