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 sys = require("sys"), sax = require("../sax-js/lib/sax"); | |
parser = sax.parser(false); | |
sax.EVENTS.forEach(function (ev) { | |
parser["on" + ev] = function (n) { sys.puts(ev + " " + sys.inspect(n)); }; | |
}); | |
parser.write("<span>Welcome,</span> to monkey land").close(); | |
/* | |
$ node sax-test.js | |
opentag { |
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( request, response ) { | |
/* Determine Encoding */ | |
var isGzip = /gzip/.test( request.headers['accept-encoding'] ) ? true : false; | |
/* Extract Scope */ | |
var sandbox = /\.+(.+)\.sb+/.exec( request.headers.host ); | |
if ( sandbox !== null ) { | |
var scope = sandbox[1]; |
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
// This returns a Javascript string | |
require.registerExtension('.coffee', function(async, source, callback) { | |
return compileCoffee(source); | |
}); | |
// True | |
require('coffee').test === 123; | |
// This returns a object | |
require.registerExtension('.mu', function(async, source, 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
var sys = require('sys'); | |
var url= require('url'); | |
var query = url.parse('http://www.freddymac.com?name=freddy&lastname=mac', true).query; | |
sys.puts(query.name); // -> freddy | |
// or use querystring directly: | |
var querystring = require("querystring"); | |
var query = querystring.parse("name=joe&lastname=schmoe"); | |
sys.puts(query.name); // -> joe |
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
-- I used to do it like this: | |
SELECT * FROM table WHERE | |
hurr | |
AND (foo = 'bar') | |
AND (bar = 'foo') | |
-- Then later I spaced it out even more: | |
SELECT |
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
// no global leakage this way | |
function createNamedFunction(name) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
var code = args.pop(); | |
return process.compile("(function "+name+"("+args.join(",")+"){"+body+"\n})" | |
, "createNamedFunction-"+name); | |
} |
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
// this is an example of what the first pass at native (fab) templates will look like: | |
with ( require( "fab" ) ) fab | |
( listen, 0xFAB ) | |
( /\// ) | |
( /1/ ) | |
( "This is a template with no variables: a unary app" ) |
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
// this is an example of what the first pass at native (fab) templates will look like: | |
var fab = require("fab") | |
, listen = fab.listen | |
( fab ) | |
( listen, 0xFAB ) | |
( /\// ) |
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 n = 45 | |
, sys = require("sys") | |
sys.puts(typeof n); // number | |
sys.puts(n instanceof Number); // false | |
var m = Number(45); | |
sys.puts(typeof m); // number |
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 readAllHelps (cb) { | |
var help_text = [] | |
, didError = false | |
function error (er) { | |
if (didError) return undefined | |
didError = true | |
cb(er) | |
} | |
fs.readdir('help', function(er, files) { | |
if (err) return error(er) |