Skip to content

Instantly share code, notes, and snippets.

Last login: Fri Sep 16 12:55:55 on ttys001
Enki:~ $ node
> var places = ['cha-ya', 'pica pica', 'herbivore', 'sunflower']
> console.log(places[Math.floor(Math.random() * 4)])
pica pica
@sh1mmer
sh1mmer / gist:978658
Created May 18, 2011 14:20
Request Skeleton
//Server CommonJS Module Skeleton
var sys = require('sys'),
EE = require('events').EventEmitter;
var Server = exports.Server = function() {
//Server Setup
};
sys.inherits(Server, EE);
Server.prototype.Request = function() {
var cp = require('child_process');
var child = cp.spawn('cat', [], {customFds:[0, 1, 2]});
child.stdout.on('data', function(d) {
console.log(d);
});
/Users/croucher/Code/node/wscript: error: Traceback (most recent call last):
File "/Users/croucher/Code/node/tools/wafadmin/Utils.py", line 274, in load_module
exec(compile(code, file_path, 'exec'), module.__dict__)
File "/Users/croucher/Code/node/wscript", line 38, in <module>
import js2c
File "/Users/croucher/Code/node/tools/js2c.py", line 41, in <module>
import jsmin
ImportError: Bad magic number in /Users/croucher/Code/node/tools/jsmin.pyc
@sh1mmer
sh1mmer / The Koan of Closure
Created December 15, 2010 22:18
Programming Koans
The venerable master Qc Na was walking with his student, Anton. Hoping to
prompt the master into a discussion, Anton said "Master, I have heard that
objects are a very good thing - is this true?" Qc Na looked pityingly at
his student and replied, "Foolish pupil - objects are merely a poor man's
closures."
Chastised, Anton took his leave from his master and returned to his cell,
intent on studying closures. He carefully read the entire "Lambda: The
Ultimate..." series of papers and its cousins, and implemented a small
Scheme interpreter with a closure-based object system. He learned much, and
EE = require('events').EventEmitter;
ee = new EE();
die = false;
ee.on('die', function() {
die = true;
});
while(!die) {
var sys = require("sys"),
http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs");
function getHostname(str) {
var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');
return str.match(re)[1].toString();
}
var hardBlockedIps = [];
hardBlockedIps.push({ip: '127.0.0.1', undefined}); // block 127.0.0.1 forever
hardBlockedIps.push({ip: '10.0.0.1', 1283223005549}); // block 10.0.0.1 until time stamp expires
for (var i=0;i<hardBlockedIps.length;i++){
if (req.connection.remoteAddress === hardBlockedIps[i].ip) {
if (hardBlockedIps[i].expires !== undefined && (new Date).getTime() > hardBlockedIps[i].expires) {
console.log("Hard Block on IP " + hardBlockedIps[i].ip + " expired");
break;
} else {
req.connection.end();
#!/usr/bin/env node
// the upstart job to check the status of
var job = 'node';
var spawn = require('child_process').spawn,
status = spawn('status', [job]),
output = "";
status.stdout.on('data', function(data) {
From noreply@monitor.cloudkick.com Mon Aug 23 23:32:40 2010
X-RocketMail: 00000004;R---S-----H-----;8771
X-RocketUID: 0000000000
X-RocketYMUMID: AJfPjkQAAX1sTHMFGQjvOg0irtA
X-RocketMIF: 1282606361;2296;
X-Apparently-To: tom_croucher@yahoo.com via 68.142.207.151; Mon, 23 Aug 2010 16:32:41 -0700
X-RocketRCL: ;;;513
Return-Path: <noreply@monitor.cloudkick.com>
X-RocketTIP: 173.45.246.193 ; NO_TIP_HEADER_ALLOWED ;
X-RocketSRV: s_ip=173.45.246.193;d_t=1282606361;url=75.101.185.99,http://75.101.185.99:,tomhughescroucher.com,http://tomhughescroucher.com/;Retro=Y;SgrnP=N