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
function assert(res, expected) { | |
var result = rpn(res); | |
if (result !== expected) { | |
throw new Error('Not equals: ', result); | |
} | |
} | |
function apply(operator, opd1, opd2) { | |
var str = 'return ' + opd1 + operator + opd2 + ';'; | |
return (new Function(str))(); | |
} |
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
function pad(str,num) { return str.length < num ? pad('0' + str,num) : str; } | |
function dec2bin(num) { | |
return num <= 1 ? '' + num : dec2bin(Math.floor(num>>1)) + '' + (num & 1); // n % d == n & (d-1) if d is a power of two | |
} | |
function binaryClock(d) { | |
var binLen = 4, //Binary digit length including paddying | |
bin = (pad('' + d.getHours(),2) | |
+ pad('' + d.getMinutes(),2) | |
+ pad('' + d.getSeconds(),2) ).split('') //string of time digits to array | |
.map(function (n) { return pad(dec2bin(+n), binLen).split(''); }); //Conv and pad digits |
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
function pad(str,num) { return str.length < num ? pad(0 + str,num) : str; } | |
function binaryClock(d) { | |
var bin = (pad('' + d.getHours(),2) | |
+ pad('' + d.getMinutes(),2) | |
+ pad('' + d.getSeconds(),2) ).split('') //string of time digits to array | |
.map(function (n) { return pad((+n).toString(2),4) }), //conv to binary and pad | |
i,j,str=''; | |
for (i = 0; i<4; i++) { | |
for (j = 0; j<bin.length; j++) { |
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
/*jslint devel: true, bitwise: true, continue: true, debug: true, eqeq: true, | |
plusplus: true, vars: true, white: true */ | |
/* | |
* Christian Delahousse | |
* Binary Clock | |
* May 27,2012 | |
*/ | |
(function () { | |
'use strict'; | |
function dec2bin(dec) { |
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
//if JS running in Rhino | |
if (typeof Packages === "object" && String(Packages) === "[JavaPackage ]") { | |
load('init.js'); | |
} | |
/* | |
* Christian Delahousse | |
* Programming Praxis | |
* Galton Machine Simulation | |
* http://programmingpraxis.com/2012/04/10/galton/ | |
*/ |
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
#!/usr/bin/env sh | |
## | |
# This is script with usefull tips taken from: | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# | |
# install it: | |
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh | |
# |
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
;Recursive | |
(define (fib n) | |
(cond ((eq? n 0) 0) | |
((eq? n 1) 1) | |
(else (+ (fib (- n 2)) | |
(fib (- n 1)))))) | |
;Iterative | |
(define (fib n) | |
(define (iter n-1 n-2 count) |