Skip to content

Instantly share code, notes, and snippets.

var Flow = require('make-flow')
// definition
var app = Flow()
.def('sum1', function (done) {
add(1, 2, done)
})
.def('sum2', function (done) {
add(3, 4, done)
})
.def('result', function (sum1, sum2, done) {
#!/usr/bin/env sh
# Library version
VERSION="0.7.3"
N_PREFIX=${N_PREFIX-/usr/local}
VERSIONS_DIR=$N_PREFIX/n/versions
#
# Log the given <msg ...>
@eldargab
eldargab / gist:4252184
Created December 10, 2012 18:02
prompt with git branch
function git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \(\1\)/'
}
PS1="\W\$(git_branch) $ "
@eldargab
eldargab / gist:3777055
Created September 24, 2012 17:11
throttle function
function throttle (fn, timeout) {
var ctx, args, wait = false
return function () {
if (wait) {
ctx = this
args = arguments
return
}
wait = true
@eldargab
eldargab / gist:3656269
Created September 6, 2012 13:30
Thoughts on using mocking, spying libraries like sinon for testing

Thoughts on using mocking, spying libraries for testing.

While using sinon extensively I realized that in most cases it's better to write assertions and define behaviors just right in a fake function:

it('Should list dir contents', function (done) {
  fs.readdir('dir', function (err, list) {
    should.not.exist(err)
    list.should.eql(['a', 'b', 'c'])
    done()
@eldargab
eldargab / bench.js
Created April 20, 2012 15:22 — forked from chowey/bench.js
Benchmark str concatenation
var Benchmark = require('benchmark')
var suite = new Benchmark.Suite
suite
.add('push', function () {
var a = []
a.push("Lorem")
a.push("ipsum")
a.push("dolor")
@eldargab
eldargab / expose-to-browser.ps1
Created March 5, 2012 15:18
Wrap commonJS file for use in browser
param(
$file,
$global
)
function camelize ($s) {
($s -Split "[\-_]", 0, "RegexMatch" | foreach {
$_.Substring(0, 1).toUpper() + $_.Substring(1)
}) -Join ""
}