Skip to content

Instantly share code, notes, and snippets.

Bruno Jouhier bjouhier

Block or report user

Report or block bjouhier

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bjouhier
bjouhier / requestBug.js
Created May 27, 2011
Compiled version of requestBug_.js
View requestBug.js
/*** Generated by streamline 0.1.22 - DO NOT EDIT ***/
var __global = typeof global !== 'undefined' ? global : window;
function __cb(_, fn) { var ctx = __global.__context; return function(err, result) { __global.__context = ctx; if (err) return _(err); try { return fn(null, result); } catch (ex) { return __propagate(_, ex); } } }
function __future(fn, args, i) { var done, err, result; var cb = function(e, r) { done = true; err = e, result = r; }; args = Array.prototype.slice.call(args); args[i] = function(e, r) { cb(e, r); }; fn.apply(this, args); return function(_) { if (done) _.call(this, err, result); else cb = _.bind(this); }.bind(this); }
function __propagate(_, err) { try { _(err); } catch (ex) { __trap(ex); } }
function __trap(err) { if (err) { if (__global.__context && __global.__context.errorHandler) __global.__context.errorHandler(err); else console.error("UNCAUGHT EXCEPTION: " + err.message + "\n" + err.stack); } }
(function(_) {
var __then = (_ = (_ || __trap));
/* 1
@bjouhier
bjouhier / requestBug_.js
Created May 27, 2011
Demonstrates problem when more than 4 HTTP client requests are sent in parallel
View requestBug_.js
var streams = require("streamline/lib/streams/streams");
var flows = require("streamline/lib/util/flows");
var port = 3001;
// if you remove last element, test will pass!
var values = [1,2,3,4,5];
function send(_, path, val){
return streams.httpRequest({
method: "put",
url: "http://localhost:" + port + path
@bjouhier
bjouhier / rimraf.js
Created Aug 8, 2011 — forked from laverdet/rimraf.js
rimraf with futures
View rimraf.js
/*** Generated by streamline 0.1.35 - DO NOT EDIT ***/
var __global = typeof global !== 'undefined' ? global : window;
function __cb(_, fn){ var ctx = __global.__context; return function(err, result){ __global.__context = ctx; if (err) return _(err); try { return fn(null, result); } catch (ex) { return __propagate(_, ex); } } }
function __future(fn, args, i){ var done, err, result; var cb = function(e, r){ done = true; err = e, result = r; }; args = Array.prototype.slice.call(args); args[i] = function(e, r){ cb(e, r); }; fn.apply(this, args); return function(_){ if (done) _.call(this, err, result); else cb = _.bind(this); } .bind(this); }
function __nt(_, fn){ var i = 0; var cb = __cb(_, fn); var safeCb = function(){ try { cb(); } catch (ex) { __propagate(cb, ex); } }; if (typeof process != "undefined" && typeof process.nextTick == "function") return function(){ if (++i % 20 == 0) process.nextTick(safeCb); else cb(); }; else return function(){ if (++i % 20 == 0) setTimeout(safeCb); else cb(); }; }
function _
View jsurlbench.js
"use strict";
var JSURL = require("jsurl");
function bench(name, count, fn) {
var t0 = Date.now();
for (var i = 0; i < count; i++)
fn();
console.log(name + ": " + (Date.now() - t0));
}
@bjouhier
bjouhier / callrepro
Created Dec 17, 2011
fstreamline bug repro with fn.call
View callrepro
"use strict";
if (!require('streamline/module')(module)) return;
function foo(_, i) {
return 2 * i;
}
function bar(_, f, i) {
return f.call(null, _, i);
}
@bjouhier
bjouhier / tryCatchTrampo.js
Created Dec 18, 2011
Callback wrapper that implements trampoline with try/catch
View tryCatchTrampo.js
// callback wrapper for trampoline
var depth = 0;
var maxDepth = 100;
var marker = {};
function trampo(cb) {
return function(e, r) {
var d = depth++;
try {
if (depth === maxDepth)
@bjouhier
bjouhier / gist:1535403
Created Dec 29, 2011
my first ace test
View gist:1535403
#!/usr/bin/env node-streamline
"use strict";
require('coffee-script')
var test = require("ace/src/lib/ace");
test(1, function(_) {
function Foo(x, _) {
process.nextTick(_);
this.x = x;
@bjouhier
bjouhier / chomp.js
Created Feb 2, 2012
Streamlined function to concatenate several input files into one output file
View chomp.js
"use strict";
if (!require('streamline/module')(module)) return;
var fs = require('fs');
var streams = require('streamline/lib/streams/server/streams');
// cat ins > out
exports.chomp = function(ins, out, _) {
streams.usingWritable(_, fs.createWriteStream(out), function(_, outStream) {
for (var i = 0; i < ins.length; i++) {
@bjouhier
bjouhier / bench.js
Created Feb 13, 2012
Simple bench of basic JS constructs
View bench.js
function bench(name, fn) {
var result;
// 2 passes to let V8 optimize
for (var pass = 2; pass >= 0; pass--) {
var count = 1;
while (true) {
var t0 = Date.now();
fn(count);
dt = (Date.now() - t0);
if (dt > 100) {
@bjouhier
bjouhier / needsTrampoline.js
Created Mar 9, 2012
Simple code that breaks without trampoline
View needsTrampoline.js
if (!require('streamline/module')(module)) return;
function fibo(_, n) {
return n > 1 ? fibo(_, n - 1) + fibo(_, n - 2) : 1;
}
function fibo2(_, n) {
return n > 1 ? trampo(this, 0, fibo2, _, n - 1) + trampo(this, 0, fibo2, _, n - 2) : 1;
}
You can’t perform that action at this time.