Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / gist:8073619
Created December 21, 2013 19:16
Pone la hora de finalización al lado del artículo
javascript:[].filter.call(document.getElementsByClassName("g-clTRght"), function (e) {
return /^[0-9]+[hHmMsM]/.test(e.innerHTML);
}).forEach(function (e) {
var r, h, p, hora, minuto, segundo;
var txt= e.innerHTML;
if (/^[0-9]+[hH]/.test(txt)) {
r= /^([0-9]+)[hH] ([0-9]+)[mM]/.exec(txt);
h= new Date(Date.now() + (r[1]*60*60*1000) + (r[2]*60*1000));
}
else if (/^[0-9]+[mM]/.test(txt)) {
@xk
xk / ManipulateStackFrameReturnAddress.c
Last active August 29, 2015 13:56
Manipulate the stack frame return address
//2014-02-09 jorge@jorgechamorro.com
//Manipulate the stack frame return address
#include <stdio.h>
#include <string.h>
void uno () {
char** r= (char**) &r+2;
while (**r != '\x90') (*r)++;
@xk
xk / StackFrameGarbage.c
Created February 9, 2014 17:47
stack frame garbage
//2014-02-09 jorge@jorgechamorro.com
//stack frame garbage
#include <stdio.h>
void uno () {
char a[18]= "GeorgeOfTheJungle";
}
void dos () {