Skip to content

Instantly share code, notes, and snippets.

View cdelahousse's full-sized avatar

Christian Delahousse cdelahousse

View GitHub Profile
@cdelahousse
cdelahousse / fibonacci.scm
Created January 18, 2012 07:27
Fibonacci Implementation
;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)
@cdelahousse
cdelahousse / hack.sh
Created April 1, 2012 19:55 — forked from erikh/hack.sh
OSX For Hackers
#!/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
#
@cdelahousse
cdelahousse / Galton Machine Simulation
Created April 19, 2012 05:41
I created a simple Galton Machine simulation. It is used to demonstrate the central limit theorem.
//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/
*/
@cdelahousse
cdelahousse / binclock.js
Created May 28, 2012 00:05
JS Binary Clock
/*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) {
@cdelahousse
cdelahousse / binaryClock2.js
Created June 3, 2012 02:35
Binary clock version two, reimplemented to be shorter
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++) {
@cdelahousse
cdelahousse / BinaryClock3.js
Created June 4, 2012 05:14
Third, overly clever, reimplementation of a binary coded clock
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
@cdelahousse
cdelahousse / rpn
Last active August 29, 2015 14:03
Reverse Polish Notation Math Expression Parser
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))();
}