Skip to content

Instantly share code, notes, and snippets.

(defn mostly-small-nonempty-subset
"Returns a subset of the given collection, with a logarithmically decreasing
probability of selecting more elements. Always selects at least one element.
(->> #(mostly-small-nonempty-subset [1 2 3 4 5])
repeatedly
(map count)
(take 10000)
frequencies
sort)
@cemerick
cemerick / gist:9207672
Created February 25, 2014 12:07
go-loop fail
; Clojure 1.6.0-alpha3, CLJS HEAD, [org.clojure/core.async "0.1.267.0-0d7780-alpha"]
; works
(go (loop [change (<! dom-change-chan)]
(when change
(js/console.log change)
(recur (<! dom-change-chan)))))
; doesn't work
(go-loop [change (<! dom-change-chan)]
expr -- (void)printf("[%s %s]\n",(char *) object_getClassName(*(long*)($rdi)), (char *)($rsi))
(add-to-list 'auto-mode-alist (cons "COMMIT_EDITMSG"
(lambda ()
(text-mode)
(setq fill-column 72)
(auto-fill-mode 1))))
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@jboner
jboner / latency.txt
Last active July 7, 2024 21:35
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
@hugoduncan
hugoduncan / gist:1033762
Created June 19, 2011 04:36
Use aether for artifact resolving
(ns pallet.aether
"Wrapper for aether resolution
See:
https://docs.sonatype.org/display/AETHER/Home"
(:require
[clojure.java.io :as io]
[clojure.contrib.logging :as logging])
(import
org.apache.maven.repository.internal.MavenRepositorySystemSession
@Chouser
Chouser / proxy-star.clj
Created March 15, 2011 21:22
Like clojure.core/proxy, but accepts a syntax like reify
(let [arrays '{objects "Ljava.lang.Object;",
ints I, longs J, floats F, doubles D, chars C,
shorts S, bytes B, booleans Z}]
(defn qualify-tag [tag]
(when tag
(let [cls (if-let [array (arrays tag)]
(clojure.lang.RT/classForName (str "[" array))
(resolve tag))]
(assert (class? cls))
(symbol (pr-str cls))))))
@koraktor
koraktor / git-create-empty-branch.sh
Created March 26, 2009 08:04
Git: Creating an empty branch
git stash # Stash changes if any
git symbolic-ref HEAD refs/heads/${NEW_BRANCH} # Change head to a new, non-existing ref
git rm -rf . # Delete files from version control and working directory
rm -r . # Delete files from file system
git commit --allow-empty -m "Created new branch ${NEW_BRANCH}" # Commit changes in the new branch