Skip to content

Instantly share code, notes, and snippets.

View AlexAti's full-sized avatar

Alex Ati AlexAti

View GitHub Profile
@flyingmachine
flyingmachine / gist:4004807
Created November 2, 2012 22:41
clojure korma heroku db connection
(defdb db
(if (System/getenv "DATABASE_URL")
(let [db-uri (java.net.URI. (System/getenv "DATABASE_URL"))
user-and-password (clojure.string/split (.getUserInfo db-uri) #":")]
{:classname "org.postgresql.Driver"
:subprotocol "postgresql"
:user (get user-and-password 0)
:password (get user-and-password 1) ; may be nil
:subname (if (= -1 (.getPort db-uri))
(format "//%s%s" (.getHost db-uri) (.getPath db-uri))
@jboner
jboner / latency.txt
Last active May 17, 2024 01:05
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@pingles
pingles / bytes_to_int.clj
Created September 22, 2011 17:01
Clojure code to convert a byte array to an integer
(defn bytes-to-int
([bytes]
(bytes-to-int bytes 0))
([bytes offset]
(reduce + 0
(map (fn [i]
(let [shift (* (- 4 1 i)
8)]
(bit-shift-left (bit-and (nth bytes (+ i offset))
0x000000FF)