Skip to content

Instantly share code, notes, and snippets.

View nodejs t goal
var t = require('./t');
t.app(8888, {
routes: {
'^/$': function(req, res) {
t.respond("something something");
},
'^/test/$': function() {
}
}
@torgeir
torgeir / chat.js
Created Jun 24, 2010
A simple "chat" application using Node.js
View chat.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 Aug 18, 2010
js functional+prototypal inheritance template
View js prototypal inheritance
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 Aug 22, 2010
Understanding nodejs nextTick
View 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 Oct 19, 2010
os x launchctl service
We couldn’t find that file to show.
@torgeir
torgeir / gist:633864
Created Oct 19, 2010
colored git diff
View gist:633864
git config --global color.diff always
View bash colors
for i in $(seq 1 10); do echo -n $(tput setaf ${i}) ${i}; done
@torgeir
torgeir / scope.js
Created Nov 11, 2010
JavaScript owns your scope
View scope.js
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 Mar 11, 2011
node.js proxy
View proxy.js
// 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'
View gist:879167
#!/bin/sh
# Opens a git repo for people to pull/push
git daemon --reuseaddr --base-path=/ --export-all --verbose --enable=receive-pack
You can’t perform that action at this time.