Skip to content

Instantly share code, notes, and snippets.

@xk
xk / status.js
Created September 12, 2011 23:27
app status
var appStatus;
process.on('uncaughtException', function globalErrHandler (error) {
console.log('An error happened when the appStatus was '+ appStatus);
switch (appStatus) {
case 1: //recover from status 1
case 2: //idem from status 2
case 3: //etc.
@xk
xk / timers.js
Created September 14, 2011 09:13
test node's timers
// 2011-09-15 jorge@jorgechamorro.com
// http://groups.google.com/group/nodejs-dev/msg/cf392e131b5fcd3a
// http://groups.google.com/group/nodejs-dev/browse_thread/thread/922a30cf88a1b784
var ms= 5;
var ctr= 0;
var RUN= 1;
function f () {
if (RUN) {
@xk
xk / SubArray.js
Created October 28, 2011 06:59 — forked from CrabDude/SubArray.js
Node.js Array subclass
// 20111028 jorge@jorgechamorro.com
// How to subclass Array
// In reply to https://gist.github.com/1100841/9c959db9314338a09c0f288c2c0ca5553816e400
function subArray () {
var nu= Array.apply(null, arguments);
nu.__proto__= subArray.prototype;
return nu;
}
@xk
xk / nextTick.js
Created December 22, 2011 21:39
nextTick.js
/*
2012-04-22 jorge@jorgechamorro.com
MacBookPro5,4 core2duo @ 2.53GHz, node v0.7.5:
loopsPerSecond: 103412616.3, nextTicksPerSecond: 671885.8, ratio: 153.9x times faster
beagleboard beaglebone @ 500Mhz:
loopsPerSecond: 6781040.2, nextTicksPerSecond: 27472.4, ratio: 246.8x times faster
*/
@xk
xk / gist:2001931
Created March 8, 2012 16:29
Install threads-a-gogo
jorge@UbuntuParallels:~$ git clone http://github.com/xk/node-threads-a-gogo.git
Cloning into node-threads-a-gogo...
remote: Counting objects: 112, done.
remote: Compressing objects: 100% (90/90), done.
remote: Total 112 (delta 16), reused 112 (delta 16)
Receiving objects: 100% (112/112), 59.80 KiB | 84 KiB/s, done.
Resolving deltas: 100% (16/16), done.
jorge@UbuntuParallels:~$ cd node-threads-a-gogo/
jorge@UbuntuParallels:~/node-threads-a-gogo$ node-waf configure install
@xk
xk / fib.js
Created March 13, 2012 20:27 — forked from ry/fib.js
a proper fibonacci server in node. with threads_a_gogo
var http = require('http')
var pool = require('threads_a_gogo').createPool(5).all.eval(fib);
function fib (n) {
if (n < 2) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}
@xk
xk / pdfkit.rotate.js
Created March 28, 2012 11:18
doc.rotate(90) fails
var PDFDocument= require('pdfkit');
var doc= new PDFDocument();
doc.save();
doc.x= doc.pages[0].width/2;
doc.y= doc.pages[0].height/2;
doc.fontSize(30);
doc.rotate(89.9, {origin: [doc.x, doc.y]});
doc.text('OK, GOOD');
@xk
xk / bench.js
Created April 11, 2012 21:00
When threads_a_gogo beats node 2 to 1
/*
$ node bench.js
Threads_a_gogo JS thread -> 4624 (ms) 298607040
Node's main JS thread -> 8471 (ms) 298607040
Ratio: 1.83 times faster
*/
function fib (n) {
@xk
xk / keys.js
Created May 19, 2012 11:07
7M keys hash and GC hiccups
// 2012-05-19 jorge@jorgechamorro.com
var o;
function boot () {
o= {};
var i= 7e6;
while (i--) {
var key= i.toString(36);
o[key]= { id:key };
}
@xk
xk / none.sh
Created May 30, 2012 22:56
threads_a_gogo install
unibody:node-threads-a-gogo jorge$ which node
/Users/jorge/JAVASCRIPT/binarios/bin/node
unibody:node-threads-a-gogo jorge$ node -v
v0.6.17
unibody:node-threads-a-gogo jorge$ node -e 'console.log(process.versions)'
{ node: '0.6.17',
v8: '3.6.6.25',
ares: '1.7.5-DEV',
uv: '0.6',
openssl: '0.9.8l' }