Skip to content

Instantly share code, notes, and snippets.

@xk
xk / timers.js
Created September 28, 2013 12:13
Shows that node's timers are borken and execute out of order.
(function run () {
//2013.09.27 jorge@jorgechamorro.com
//Shows that node's timers are borken and often execute out of order
console.log('\nBEGIN');
var MAX= 666;
var last= 0;
var items= 0;
var errores= 0;
@xk
xk / plistread.js
Last active December 10, 2015 09:19 — forked from juanfal/plistread.rb
//plistread.js, 2012-12-30 jorge@jorgechamorro.com
var plist= require('plist');
var shell= require('child_process').exec;
var puts= console.log;
//process.argv[0] -> "node"
//process.argv[1] -> "plistread.js"
//process.argv[2] -> inputFile
//process.argv[3..n] -> property list keys
@xk
xk / buscarVariablesGlobales.js
Created November 5, 2015 13:09
Muestra las variables globales
(function buscarVariablesGlobales (dirtySet, cleanSet) {
//© 2013-02-19 jorge@jorgechamorro.com
dirtySet= document.body.appendChild(document.createElement('iframe'));
cleanSet= Object.getOwnPropertyNames(dirtySet.contentWindow);
dirtySet.parentNode.removeChild(dirtySet);
dirtySet= Object.getOwnPropertyNames(function () { return this }());
return dirtySet.filter(function (v,i,o) { return cleanSet.indexOf(v) < 0 });
})()
@xk
xk / Output on OS X Snow Leopard
Created November 4, 2012 09:58 — forked from bigeasy/Output on Fedora 16
Node.js Millisecond Timeout
$ node timers.js
setInterval(ƒ,1) -> (µs) :
[ 1477,
1172,
1071,
1084,
1122,
1145,
1064,
1062,
@xk
xk / test.js
Created September 13, 2012 13:58
this_is_a_test
//2012-09-13 jorge@jorgechamorro.com
var ctr, i, t, k= 1e8;
function ƒ (i) { ctr+= i }
function begin () { i= k, ctr= 0; while (Date.now() === (t= Date.now())) ; }
function end (s,t) { console.log(s+ ((Date.now()- t)*1e6/k).toFixed(2)+ 'ns') }
begin();
@xk
xk / js_vs_c.js
Created July 6, 2012 18:59
js_vs_c.js
//2012-06-28 js_vs_c.js
var c= 0;
var t= Date.now()+1e3;
while (c++, (now= Date.now()) < t) ;
console.log(c);
@xk
xk / js_vs_c.c
Created July 6, 2012 19:03
js_vs_c.c
//2012-06-28 js_vs_c.c
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
long long DateNow () {
struct timeval time;
gettimeofday(&time, NULL);
return (long long) ((time.tv_sec* 1000000) + time.tv_usec);
@xk
xk / functionCall.c
Created June 28, 2012 14:43
To call() or not to call() that is the question.
//2012-06-28 functionCall.c jorge@jorgechamorro.com
/*
$ gcc -O0 /Users/jorge/Desktop/functionCall.c
$ ./a.out
without a function call: 2.789478 ns per iteration
with a function call : 3.574004 ns per iteration
With the function call it's 28.124473 percent slower than without the function call
*/
@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' }
@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 };
}