This file contains hidden or 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
process.mixin(require('sys')); | |
var Persistance = require('./persistance'); | |
var db; | |
// Can use a mongodb server as the backend | |
db = new Persistance.Backend('mongodb://localhost/blog'); | |
// Can use a postgres server as the backend | |
db = new Persistance.Backend('postgresql://user:pass@localhost:5432/blog'); | |
// Can use a sqlite database file |
This file contains hidden or 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
class Dispatcher | |
# Remove the cruft to try to keep the options clear | |
instance_methods.each { |m| undef_method m unless m =~ /^__|instance_variable_?e?|object_id|inspect|dup/ } | |
# Store the callback and initialize the route | |
def initialize(&block) | |
@route = [] | |
@block = block | |
end |
This file contains hidden or 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'); | |
function Sqlite(path) { | |
var conn = process.createChildProcess("sqlite3", ['-batch', '-header', '-nullvalue', "\r", '-separator', "\t", path]), | |
queue = [], dequeued = 0, | |
callback, want_close = false; | |
function parse(string) { | |
var raw, headers; | |
// Parse the output into cells. newline for row, tab for field, and |
This file contains hidden or 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
// combo library | |
function Combo(callback) { | |
this.callback = callback; | |
this.items = 0; | |
this.results = []; | |
} | |
Combo.prototype = { | |
add: function () { | |
var self = this; | |
this.items++; |
This file contains hidden or 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
~$ coffee -i | |
coffee> process.mixin(require("sys")) | |
coffee> p | |
[Function] | |
coffee> p (x) -> x * x | |
[Function] | |
coffee> puts (x) -> x * x | |
function (x) { | |
return x * x; | |
} |
This file contains hidden or 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
process.mixin(require('sys')); | |
valid_modes = ["r", "w", "a"]; | |
var File = { | |
open: function (filename, mode) { return function (callback) { | |
debug("in open closure"); | |
mode = mode || "w"; | |
if (valid_modes.indexOf(mode) < 0) { | |
throw new Error("Invalid file mode " + JSON.stringify(mode)); |
This file contains hidden or 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
From fa8b7dc1513e03ca014d3ffd234c6d8e0c9e8d5f Mon Sep 17 00:00:00 2001 | |
From: Tim Caswell <[email protected]> | |
Date: Wed, 3 Feb 2010 12:28:05 -0600 | |
Subject: [PATCH] Use the new Object.getOwnPropertyNames to show hidden properties on inspect. Added as a second optional argument to inspect. | |
For example: | |
node> puts(inspect([1,2,3])) | |
[ | |
1, |
This file contains hidden or 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
// Imagine some library called Do that is used as follows: | |
Do.parallel( | |
users.search({"age >": 21}).addCallback, | |
file.read("pubs.txt").addCallback | |
)(function (people, text) { | |
// This function will be called after the database | |
// query and the file read are both done. | |
}); |
This file contains hidden or 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
From 151330d050405d088b357713d7c204847902be37 Mon Sep 17 00:00:00 2001 | |
From: Tim Caswell <[email protected]> | |
Date: Wed, 3 Feb 2010 20:29:13 -0600 | |
Subject: [PATCH] Bind the addCallback function on File.read and File.write so we can use it in any context. | |
--- | |
lib/file.js | 19 ++++++++++++++++--- | |
1 files changed, 16 insertions(+), 3 deletions(-) | |
diff --git a/lib/file.js b/lib/file.js |