Skip to content

Instantly share code, notes, and snippets.

(defn when-its-one []
(loop []
(if (= 1 (rand-int 2000))
1
(do
(println "foo")
(recur)))))
(defn domap [f & colls]
(let [num-colls (count colls)]
(doseq [args (partition num-colls (apply interleave colls))]
(apply f args))))
(domap println [1 2])
(domap println [1 2] [3 4])
(domap println [1 2] [3 4] [5 6])
#!/usr/bin/env ruby
#
# A hook script to verify that only syntactically valid ruby code is commited.
# Called by git-commit with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# Put this code into a file called "pre-commit" inside your .git/hooks
# directory, and make sure it is executable ("chmod +x .git/hooks/pre-commit")
#
-module(test_helper).
-export([riak_test/1]).
riak_test(Fun) ->
start_riak(),
{ok, Riak} = riak:local_client(),
Ret = (catch Fun(Riak)),
stop_riak(),
case Ret of
@pjstadig
pjstadig / calculate.clj
Created July 25, 2011 19:35 — forked from mjg123/calculate.clj
Why can't I recur here?
(defn calculate
"A list of coin-values from coins, which sum to target"
[coins target acc]
(let [coin (max-coin coins target)]
(recur coins
(- target coin)
(cond
(not coin) (js-alert "No solution")
(= coin target) (list coin)
(< coin target) (cons coin acc))))
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(set! *warn-on-reflection* true)
@pjstadig
pjstadig / gist:2596392
Created May 4, 2012 17:30 — forked from ddillinger/gist:2258880
Conkeror on Unity
@pjstadig
pjstadig / latency.markdown
Created June 7, 2012 19:45 — forked from hellerbarde/latency.markdown
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

@pjstadig
pjstadig / midirepl.clj
Created July 13, 2012 19:57 — forked from alandipert/midirepl.clj
Midi REPL
(import '(javax.sound.midi MidiSystem Synthesizer))
(def keymaps
'{:colemak {a 60
r 62
s 64
t 65
d 66
h 67
n 68
@pjstadig
pjstadig / nrepl.sh
Created September 28, 2012 17:55 — forked from hiredman/nrepl.sh
shell + clojure
#!/bin/sh
#_(
exec "/home/root/jdk1.7.0_06/bin/java" -Dfile.encoding=utf8 -cp clojure-1.5.0-master-SNAPSHOT.jar:tools.nrepl-0.2.0-beta8.jar clojure.main $0
#{})
(use '[clojure.tools.nrepl.server :only (start-server stop-server)])
(defonce server (start-server :port 7888))
(println "nrepl is running")