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
//20110308 jorge@jorgechamorro.com | |
Object.defineProperty(thePrototype, 'parsedUrl', { | |
get: function () { | |
var parsed= url.parse(this.url, true); | |
this.__proto__= null; // cuts momentarily the proto chain | |
this.parsedUrl= parsed; // shadows the getter | |
this.__proto__= thePrototype; // restores the proto chain | |
return parsed; | |
} |
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
// testing the effect of using an ES5 Getter | |
// to get the parsedUrl on an object | |
var url = require("url") | |
function AutoParseUrl (u) { | |
this.url = u | |
} | |
Object.defineProperty(AutoParseUrl.prototype, "parsedUrl", {get:function () { | |
return url.parse(this.url) |
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 a= 'a'; | |
var kMaxLength= Math.pow(2,27); | |
while (a.length < kMaxLength) { | |
a= [a,a].join(''); | |
console.log("*** BEGIN -> " + a.length); | |
console.log(a); | |
console.log("*** END -> " + a.length); |
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 a= 'a'; | |
var kMaxLength= 8192; | |
do a= [a,a].join(''); while (a.length < kMaxLength); | |
var i= 1e4; | |
while (i--) console.log(a); | |
a= null; |
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 str = ''; | |
var n= 1024*1024; | |
var i = n; | |
while (i--) str += "C"; | |
console.log('str.length -> ' + str.length); | |
var maxT= -1; | |
var save= []; |
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
/* | |
problem.js, 20110417 jorge@jorgechamorro.com | |
Demonstrates a problem in Buffer.prototype.write() with cons-strings (also known as ropes) | |
run this as node --trace-gc problem.js | |
and you'll see that too often the buf.write() takes ~ 50x times as long to complete (marked as '**** BAD'). | |
After a GC cycle it returns to normal/good for a little while. |
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
curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.13.tar.gz | |
% Total % Received % Xferd Average Speed Time Time Time Current | |
Dload Upload Total Spent Left Speed | |
100 433k 100 433k 0 0 91366 0 0:00:04 0:00:04 --:--:-- 101k | |
MacBookUniBody:JAVASCRIPT jorge$ tar xzf autoconf-2.13.tar.gz | |
MacBookUniBody:JAVASCRIPT jorge$ cd autoconf-2.13 | |
MacBookUniBody:autoconf-2.13 jorge$ ./configure --prefix=/usr/local --program-suffix=213 | |
creating cache ./config.cache | |
checking for gm4... /usr/bin/gm4 | |
checking for mawk... no |
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
// sets kCount timeouts of no more than 5 ms using floats and using integers | |
// and logs the times at which they are actually triggered. | |
var t0; | |
var log= []; | |
var kCount= 20; | |
function go () { | |
var i= kCount; | |
var cb= f('FLOAT'); |
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
/* | |
problem2.js, 20110501 jorge@jorgechamorro.com | |
to run: $node --expose-gc problem2.js | |
problem2.js is just like problem.js, but does a gc() whenever a BAD happens. | |
After the gc() it runs fine again for quite while, so the problem must have something to do with the GC. | |
****************** |
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 crypto = require('crypto'); | |
var key = "some keys are better than others"; | |
var msg = "Attack Troy from within a wooden horse!"; | |
var CYPHER = "aes256"; | |
var test = function(msg) { | |
var cypher = crypto.createCipher(CYPHER, key); | |
var enc_msg = cypher.update(msg, "utf8", 'binary'); | |
enc_msg += cypher.final('binary'); |