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
| 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); }); | |
| }; | |
| } |
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
| (function() { | |
| // Module scope | |
| var global = this; | |
| // Private methods hook | |
| var private = {}; | |
| // Helper functions | |
| function foo() { | |
| return "Helper foo"; |
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
| (function() { | |
| // Module scope | |
| var global = this; | |
| // Helper functions | |
| function foo() { | |
| return "module foo"; | |
| } | |
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
| (function() { | |
| // Module scope | |
| var global = this; | |
| // Helper functions | |
| function foo() { | |
| return "module foo"; | |
| } | |
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
| (function() { | |
| // Module scope | |
| var global = this; | |
| // Helper functions | |
| function foo() { | |
| } | |
| var Widget = function (elementId, options) { | |
| this.scope = "bar"; |
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 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(); | |
| }); |
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 http = require('http'), | |
| sys = require('sys'); | |
| var options = { | |
| host: 'graph.facebook.com', | |
| port: 443, | |
| path: '/me' | |
| }; | |
| http.get(options, function(response) { |
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 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'); | |
| } |
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 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() { |
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
| 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] | |
| ] | |
| } |
NewerOlder