Skip to content

Instantly share code, notes, and snippets.

var t = require('./t');
t.app(8888, {
routes: {
'^/$': function(req, res) {
t.respond("something something");
},
'^/test/$': function() {
}
}
@torgeir
torgeir / chat.js
Created June 24, 2010 17:19
A simple "chat" application using Node.js
/*
Usage:
$ node chat.js
$ curl http://127.0.0.1:8124/say?one
// say!
$ curl http://127.0.0.1:8124/say?two
// say!
$ curl http://127.0.0.1:8124/ask
// ["one", "two"]
*/
@torgeir
torgeir / js prototypal inheritance
Created August 18, 2010 13:08
js functional+prototypal inheritance template
var sys = require('sys');
var createObject = function (obj) {
function F () {};
F.prototype = obj;
return new F;
};
var button = (function () {
@torgeir
torgeir / Understanding nodejs nextTick
Created August 22, 2010 11:10
Understanding nodejs nextTick
var sys = require('sys');
var print = function print(list) {
for (var i = 0; i < list.length; i++) {
var item = list[i];
if (item.length) {
print(item);
}
else {
sys.puts(item);
@torgeir
torgeir / gist:633807
Created October 19, 2010 07:53
os x launchctl service
We couldn’t find that file to show.
@torgeir
torgeir / gist:633864
Created October 19, 2010 08:45
colored git diff
git config --global color.diff always
@torgeir
torgeir / bash colors
Created October 26, 2010 06:42
bash colors
for i in $(seq 1 10); do echo -n $(tput setaf ${i}) ${i}; done
@torgeir
torgeir / scope.js
Created November 11, 2010 08:15
JavaScript owns your scope
var a = 1;
b = 3;
var s = 1;
(function () {
a = 2;
b = 4;
var c = 3;
d = 1;
s = 2;
@torgeir
torgeir / proxy.js
Created March 11, 2011 08:31
node.js proxy
// Kjør med noe ala disse
// $ node proxy.js www.google.no 80
// $ node proxy.js www.vg.no 80
// og sjekk localhost:3000
var http = require('http')
, args = process.argv.splice(2, 2);
http.createServer(function (req, res) {
var options = {
host: args[0] || 'www.google.no'
@torgeir
torgeir / gist:879167
Created March 21, 2011 08:09
git daemon
#!/bin/sh
# Opens a git repo for people to pull/push
git daemon --reuseaddr --base-path=/ --export-all --verbose --enable=receive-pack