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 cloneFn( fn ) { | |
var | |
str = fn.toString(), | |
args = str.match( /\((.*)\)/ )[1].split(/\W+/), | |
body = str.match( /{((?:.|\n)+)}/ )[1]; | |
return Function.apply( this, args.concat( body ) ); | |
}; |
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 Dispatcher() { | |
var signatures = [], functions = []; | |
function fn() { | |
var | |
args = arguments, | |
argNo, | |
arity = args.length, |
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
captures = this.pathname.match( | |
new RegExp( "^(.*)(" + captures.join(")(.*)(") + ")(.*)$" ) | |
).slice( 1 ); | |
captures[ pos * 2 + 1 ] = val; | |
this.pathname = captures.join(""); |
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
#!/usr/bin/env node-bench | |
var list = [ | |
"foo", | |
"bar", | |
"baz", | |
"quux", | |
"asdf", | |
"qwerty", |
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
// a few ideas for unifying async "promises" | |
// there are three types of callbacks: | |
function callback( data ){ sys.puts( "called on both success and error" ) } | |
function success( data ){ sys.puts( "called on success only" ) } | |
function error( data ){ sys.puts( "called on error only" ) } | |
// for any async function, offer a single optional callback. | |
posix.cat( "config.json", 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
// thoughts for v3 of the (fab) API. | |
// | |
// each handler gets two function arguments: | |
// (1) a stream back to the last app, and | |
// (2) a stream forward to the next app, or a 404 if there is none. | |
// | |
// (i haven't figured out elegant names, so let's just call them respond for and request) | |
// | |
// all information about the request is streamed, so that you need to | |
// |
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 = require( "fab" ) | |
() | |
( "/page1", "page1" ) | |
( "/page2", "page2" ) | |
() |
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
/* | |
about (fab) v3 | |
============== | |
the first version of (fab) was mostly a toy project, to see how function | |
chaining could help create a concise javascript DSL for building web | |
apps. | |
the second version of (fab) smoothed out some edges and focused on the |
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("http").createServer( function( req, res ) { | |
res.write( "this will silently hang because sendHeader was not called" ) | |
res.close(); | |
}).listen( 8000 ) |
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 | |
assert = require( "assert" ), | |
test = require( "fab/tests" ); | |
function myBinaryApp( app ) { | |
return function() { | |
require( "sys" ).puts( "myBinaryApp called..." ) | |
return app.call( this ); | |
} | |
} |