This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
$ 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } |