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
//2014-02-09 jorge@jorgechamorro.com | |
//Cross-function var manipulation | |
#include <stdio.h> | |
#include <string.h> | |
void uno () { | |
char* b= (char*) &b; | |
while (strncmp("Ehh", b, 3)) b++; |
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
//2014-02-09 jorge@jorgechamorro.com | |
//stack frame garbage | |
#include <stdio.h> | |
void uno () { | |
char a[18]= "GeorgeOfTheJungle"; | |
} | |
void dos () { |
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
//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)++; |
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
//2014-02-10 jorge@jorgechamorro.com happy numbers in C | |
#include<stdio.h> | |
unsigned sumaCuadrados (unsigned n) { | |
unsigned d, r= 0; | |
while (n) d= n % 10, r+= d*d, n/= 10; | |
return r; | |
} |
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
//2014-02-10 jorge@jorgechamorro.com concise happy numbers JavaScript | |
function happy (n) { | |
var past= []; | |
while (n= [].reduce.call(n.toString(), function (a,n) { return a+n*n }, 0)) | |
if (n === 1) return 1; else if (past.indexOf(n) >= 0) return 0; else past.push(n); | |
} | |
for (var i=0 ; i<=100 ; ++i) happy(i) && console.log(i); |
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
//2014-02-10 jorge@jorgechamorro.com Happy Numbers JavaScript | |
function sumaCuadrados (n) { | |
var d, r= 0; | |
while (n) n-= (d= n % 10), r+= d*d, n/= 10; | |
return r; | |
} | |
function isHappy (n) { | |
while (n && n!=1 && n!=4 && n!=16 && n!=37 && n!=58 && n!=89 && n!=145 && n!=42 && n!=20) |
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
//2014-02-10 jorge@jorgechamorro.com happy numbers | |
String.prototype.reduce= [].reduce; | |
Array.prototype.has= function has (n) { return this.indexOf(n) >= 0 }; | |
Array.prototype.times= function (f,i) { for (i= this[0] ; i<=this[1] ; i++) f(i) }; | |
function happy (n) { | |
var past= []; | |
while (1) { | |
if ((n= n.toString().reduce(function(n,v){ return n+v*v },0)) === 1) return 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
/*! | |
multiline | |
Multiline strings in JavaScript | |
https://github.com/sindresorhus/multiline | |
by Sindre Sorhus | |
MIT License | |
*/ | |
(function () { | |
'use strict'; |
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 fs = require("fs"); | |
var util = require("util"); | |
function walkSync(filename, cb) { | |
try { | |
var stat = fs.lstatSync(filename); | |
if(stat.isDirectory()) { | |
try { | |
if(cb(null, filename, stat)) { | |
var files = fs.readdirSync(filename); |
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
setTimeout(function () { | |
t= Date.now()-t; | |
STOP= 1; | |
console.log(["ctr: ",ctr, ", t:", t, "ms -> ", (ctr/t).toFixed(2), "KHz"].join('')); | |
}, 2e3); | |
var ctr= 0; | |
var STOP= 0; | |
var t= Date.now()+ 2; | |
while (t > Date.now()) ; //get in sync with clock |
OlderNewer