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
frames = [ | |
[10], | |
[2,2], | |
[10], | |
[10], | |
[0,2], | |
[5,5], | |
[5,5], | |
[0,0], | |
[0,0], |
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
;; Timings are after the JVM had done all possible optimizations | |
(defn asdf [a b] (+ a b)) | |
(dotimes [x 1000] (time (dotimes [x 1000000] (+ 2 3)))) ;; "Elapsed time: 0.280724 msecs" | |
(dotimes [x 1000] (time (dotimes [x 1000000] (asdf 2 3)))) ;; "Elapsed time: 1.114747 msecs" | |
(defn asdf ^long [^long a ^long b] (+ a b)) | |
(dotimes [x 1000] (time (dotimes [x 1000000] (+ 2 3)))) ;; "Elapsed time: 0.280724 msecs" |
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
Git is Easy | |
Git is three things | |
Objects | |
Refs | |
commands - CRUD for objects and refs | |
Shadow Directory (aka index or staging area aka what the next commit will look like) | |
untracked files (files which are not in any tree object in HEAD or the shadow directory. basically, files that git doesnt know about by name) | |
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
a = -> y { -> x { x + y } } | |
a is pure | |
a[n] is pure where n is a value | |
values are pure functions | |
Typed closures are harder to think about and reason about than dynamic pure functions | |
Static type checking does not save you from reasoning about concurrency |
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
(ns mandelclj.core | |
(:gen-class) | |
(:import | |
(sun.java2d SunGraphics2D) | |
(javax.swing JFrame JLabel) | |
(java.awt.image BufferedImage) | |
(java.awt Dimension Color) | |
(java.awt.event ActionEvent | |
ActionListener | |
MouseAdapter |
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
;; Winner winner, chicken dinner. This calcs (mandel (complex. 0 0) 2000) in 15 μs after warmup | |
(deftype complex [^double real ^double imag]) | |
(defn plus | |
"(a + bi) + (c + di) == (a + b) + (c + d)i" | |
[^complex z1 ^complex z2] | |
(complex. (+ (.real z1) (.real z2)) (+ (.imag z1) (.imag z2)))) | |
(defn magnitude-squared |
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
// Do note that the following java code takes about 8-15 microseconds also | |
public class Timing { | |
public static void main(String[] Args) { | |
for(int i = 0; i < 10000; i++){ // warmup | |
thing(); | |
} | |
long start_time = System.nanoTime(); | |
thing(); | |
System.out.println(System.nanoTime() - start_time); // tends to print out 8000-15000 which is 8-15 microseconds |
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
myapp.core=> (dotimes [x 1500] (time (mandel [0.0 0.0 0.0 0.0] 0 1000))) | |
"Elapsed time: 0.311213 msecs" | |
"Elapsed time: 0.230014 msecs" ;; JVM figured out a quick optimization here | |
"Elapsed time: 0.226392 msecs" | |
"Elapsed time: 0.232127 msecs" | |
"Elapsed time: 0.228203 msecs" | |
"Elapsed time: 0.229411 msecs" | |
"Elapsed time: 0.23273 msecs" | |
"Elapsed time: 0.227901 msecs" | |
"Elapsed time: 0.226996 msecs" |
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
(def fruits ["apple" "banana" "orange" "avocado" "pepper" "pumpkin" "grape" "tomato" "blueberry" "raspberry"]) | |
(def users ["John" "Mary" "Joseph"]) | |
; You can be imperative | |
(for [i (range 0 (count fruits))] | |
(.length (fruits i))) | |
; (5 6 6 7 6 7 5 6 9 9) | |
; You can be more declarative | |
(for [fruit fruits] |
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
class Integer | |
def tags(&block) | |
-> {self.times.reduce([]) {|a, i| a << block.yield(i)}} | |
end | |
end | |
class String | |
def to_html | |
self | |
end |