Skip to content

Instantly share code, notes, and snippets.

View Orion98MC's full-sized avatar

Thierry Passeron Orion98MC

View GitHub Profile
function whenDone(callback) {
var left = 0
, done = function() { if (--left === 0) { callback(); } };
return function doThis(work, n) {
if (typeof n !== 'undefined') left += n;
else left++;
process.nextTick(function(){ work(done); });
};
}
(function() {
// Module scope
var global = this;
// Private methods hook
var private = {};
// Helper functions
function foo() {
return "Helper foo";
(function() {
// Module scope
var global = this;
// Helper functions
function foo() {
return "module foo";
}
(function() {
// Module scope
var global = this;
// Helper functions
function foo() {
return "module foo";
}
(function() {
// Module scope
var global = this;
// Helper functions
function foo() {
}
var Widget = function (elementId, options) {
this.scope = "bar";
var socket = io.connect(host, {port: port});
socket.on('route', function (data) { // data = "host:port"
console.log("routed to new host " + data);
socket.disconnect();
socket.socket.options.host = data.split(":")[0];
socket.socket.options.port = data.split(":")[1];
socket.socket.connect();
});
var http = require('http'),
sys = require('sys');
var options = {
host: 'graph.facebook.com',
port: 443,
path: '/me'
};
http.get(options, function(response) {
var fs = require('fs'), vm = require('vm'), path = require('path');
var repl = require('repl');
// Add source ability
repl.REPLServer.prototype.source = function (file) {
if (!~file.indexOf('.')) file += '.js';
if (path.existsSync(file)) {
vm.runInContext(fs.readFileSync(file).toString(), this.context);
} else {
this.outputStream.write('ERROR: file not found "' + file + '"\n');
}
var Db = require('mongodb').Db,
Connection = require('mongodb').Connection,
Server = require('mongodb').Server;
var db = new Db('mongo-test', new Server("localhost", Connection.DEFAULT_PORT, {}), {native_parser:false});
var collection; // Global collection
var onConnect = function(err, db) {
db.dropDatabase(function() {
@Orion98MC
Orion98MC / gist:840596
Created February 23, 2011 15:56
restful route spec query intereface
match '/restful_spec/:controller', :via => :get, :to => proc {|env|
routes = Rails.application.routes.routes.select{ |route| route.defaults[:controller] == env["action_dispatch.request.path_parameters"][:controller] }.collect {|route| {:verb => route.verb.to_s, :path => route.path}}
[
200,
{"Content-Type" => "text/html"},
[routes.to_json]
]
}