Skip to content

Instantly share code, notes, and snippets.

var http = require('http')
var config = {
host: '127.0.0.1',
port: 20202
}
http.createServer(function (i,o) {
o.writeHead(200, {
'Content-Type': 'text/plain'
@marcello3d
marcello3d / run_dev_server.js
Created February 11, 2011 05:42
hot swapping for node.js
/*
* This file is part of the Spludo Framework.
* Copyright (c) 2009-2010 DracoBlue, http://dracoblue.net/
*
* Licensed under the terms of MIT License. For the full copyright and license
* information, please see the LICENSE file in the root folder.
*/
/*
* based on https://github.com/DracoBlue/spludo/blob/master/build/run_dev_server.js
GridStore.prototype.getStream = function() {
var self = this;
var stream = new (require("stream")).Stream;
stream.readable = true;
process.nextTick(function() {
self.chunkCollection(function(err, collection) {
collection.find({'files_id':self.fileId}, function(err, cursor) {
function handleChunk(err, chunk) {
if (chunk) {
function complete(x,value) {
var values = arguments.callee.values;
values[x] = value;
if (++arguments.callee.completed < 2) return;
// do whatever with values
}
asyncOp("foo", function(err,data) { complete("foo",data); })
asyncOp("bar", function(err,data) { complete("bar",data); })
var waiter = new Waiter
var onlineUsers = waiter(function(done) { // done takes two arguments: (error, value)
// ... blah blah blah ...
done(err,value)
// ... blah ...
}
var latestPosts = waiter(function(done) {
// ... blah ...
// many async functions will accept 'done' as is
// ...
@marcello3d
marcello3d / gist:852909
Created March 3, 2011 15:16
mongolian_trainer output after a few runs
/usr/local/bin/node mongolian_trainer.js
Connecting to mongo://127.0.0.1:27017
Connected to mongo://127.0.0.1:27017
mongo://127.0.0.1:27017/mongolian_trainer.small count = 50
mongo://127.0.0.1:27017/mongolian_trainer.medium count = 500
mongo://127.0.0.1:27017/mongolian_trainer.large count = 50000
db names: [ 'casbah_test',
'casbahTest',
'mapper_test',
'mongolian_trainer',
@marcello3d
marcello3d / gist:854171
Created March 4, 2011 04:33
npm - github stats
[
{
"name": "ace",
"url": "https://github.com/ajaxorg/ace",
"description": "Ajax.org Cloud9 Editor",
"watchers": 415,
"forks": 84
},
{
"name": "actor",
@marcello3d
marcello3d / gist:854199
Created March 4, 2011 05:01
nithub (npm + github)
Top 50 githubbed npm modules by watchers:
1. cloud9 1349 watchers - https://github.com/ajaxorg/cloud9
2. socket.io 1089 watchers - https://github.com/LearnBoost/Socket.IO-node
3. dryice 956 watchers - https://github.com/isaacs/npm
4. npm 956 watchers - https://github.com/isaacs/npm
5. connect 948 watchers - https://github.com/senchalabs/connect
6. yui3-mocha 931 watchers - https://github.com/yui/yui3
7. yui3-core 931 watchers - https://github.com/yui/yui3
8. ukijs 663 watchers - https://github.com/voloko/uki
9. fab 539 watchers - https://github.com/jed/fab
@marcello3d
marcello3d / gist:854219
Created March 4, 2011 05:23
nithub (npmjs + github) keyword deathmatch!
ace KEYWORD DEATHMATCH
1. ace 829 score - https://github.com/ajaxorg/ace
2. vice 8 score - https://github.com/Gozala/vice
amazon KEYWORD DEATHMATCH
1. aws-lib 105 score - https://github.com/mirkok/aws-lib
2. simpledb 14 score - https://github.com/rjrodger/simpledb
3. aws 2 score - https://github.com/teemow/node-aws
apache KEYWORD DEATHMATCH
var fs = require("fs")
var sprintf = require('sprintf').sprintf
fs.readFile(__dirname+"/npmdump.json", function (err, data) {
if (err) throw err
var packages = JSON.parse(data)
fs.readFile("../output.json", function (err, data) {
if (err) throw err