Skip to content

Instantly share code, notes, and snippets.

@joshkehn
joshkehn / gist:1127734
Created August 5, 2011 15:09
WebSocket - Part 11
conn.addListener("message",
function(message)
{
sys.log("Message recieved from conn# " + conn.id + "\
" + message);
}
);
@joshkehn
joshkehn / gist:1127737
Created August 5, 2011 15:10
WebSocket - Part 12
intervals[conn] = setInterval(
function()
{
date = new Date();
conn.send(date.toString());
}
, 1000);
}
);
@joshkehn
joshkehn / gist:1127739
Created August 5, 2011 15:11
WebSocket - Part 13
server.addListener("close",
function(conn)
{
clearInterval(intervals[conn]);
server.broadcast("<"+conn.id+"> disconnected");
sys.log(conn.id + " disconnected");
}
);
var arr = // array of objects;
res = [];
arr.forEach(function (item) {
item.save(function (err) {
res.push(err);
if (res.length === arr.length)
{
// Done
}
@joshkehn
joshkehn / os_setter.js
Created August 30, 2011 01:36
One-shot setters
// One-shot set function
function error (fn)
{
// Create locally bound copy of `fn`
var handle = fn.bind(this);
// Overwrite function
error = handle;
}
@joshkehn
joshkehn / os_getter.js
Created August 30, 2011 01:37
One-shot getters
// One-shot get function
function port (number)
{
port = function () {
return number;
}
}
port(8080);
@joshkehn
joshkehn / jpcheck.js
Created August 30, 2011 21:23
Quick CLI JSON tester
var fs = require('fs'),
good = true;
var pit = fs.readFileSync(process.argv[2], 'utf8');
try {
JSON.parse(pit);
} catch (e) {
console.log('Unable to parse file.');
console.log(e);
Starting program: /Users/josh/Dropbox/Projects/algo/a.out
Reading symbols for shared libraries +. done
Stacking?
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x0000000100000da7 in push ()
/*{"mac":"1:101cf468c4fe5a158a8d0610cf4fa1b745605e2a5ae6f30118e5dfa7b44f20d3","version":"4973646","created":"2011-09-01T16:33:27Z","k":"0.9.13"}*/
/*
* The fonts and font delivery service used on this website are provided via
* Typekit, and are subject to the End User License Agreement entered into by
* the website owner. All other parties are explicitly restricted from using,
* in any manner, the Services, Licensed Fonts, or Licensed Content. Details
* about using Typekit, the EULA, and information about the fonts are listed
* below.
*
* @name FF Meta Web Pro
Exception in thread main java.lang.NullPointerException
at Bio.getMyBio(Bio.java:11)
at Bio.main(Bio.java:6)