Skip to content

Instantly share code, notes, and snippets.

View zonpantli's full-sized avatar

Miika Pihlaja zonpantli

View GitHub Profile
@zonpantli
zonpantli / gist:907577
Created April 7, 2011 11:06
functional vs imperative
// from http://kriszyp.name/2010/01/16/imperative-functional-and-declarative-programming/
// imperative
function bestPrices(inputArray){
var outputArray = [];
for(var i = 0; i < inputArray.length; i++){
if(inputArray[i].price<10){
outputArray.push(inputArray[i]);
}
}
@zonpantli
zonpantli / randoms.clj
Created February 20, 2011 17:35
generate a-count random ints with Java Random
(use 'criterium.core)
(defn randoms [seed a-count]
(let [r (Random. seed)]
(loop [vec []
cnt a-count]
(if (zero? cnt)
vec
(recur (conj vec (.nextInt r)) (dec cnt))))))
@zonpantli
zonpantli / gist:814938
Created February 7, 2011 18:50
fail fail fail
FAIL at (test_calculatrix.clj:62)
Expected: "84"
Actual: java.lang.ArrayIndexOutOfBoundsException
week2.test_calculatrix$test_main$get_output__2884.invoke(test_calculatrix.clj:17)
week2.test_calculatrix$test_main.invoke(test_calculatrix.clj:26)
week2.test_calculatrix$eval2941$fn__2944.invoke(test_calculatrix.clj:62)
week2.test_calculatrix$eval2941.invoke(test_calculatrix.clj:60)
@zonpantli
zonpantli / gist:814849
Created February 7, 2011 18:05
calculatrix (prn "dbg" line result output)
"dbg" " => 29" " 29" #<StringWriter => 29
>
"dbg" " => Invalid operand: foo" " Invalid operand: foo" #<StringWriter => Invalid operand: foo
>
"dbg" " => Invalid command: foo" " Invalid command: foo" #<StringWriter => Invalid command: foo
>
"dbg" " => 2" " 2" #<StringWriter => 2
=> 4
>
FAIL at (test_calculatrix.clj:54)