This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| 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)) { |
This file contains hidden or 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
| (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; |
This file contains hidden or 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
| //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 |