Skip to content

Instantly share code, notes, and snippets.

View puredanger's full-sized avatar
😀
Clojure is life

Alex Miller puredanger

😀
Clojure is life
View GitHub Profile
@puredanger
puredanger / gist:83f66f157f56bc9db845
Created July 19, 2015 14:28
reduce / mapv tuples
compare perf of reduce and mapv on small vectors - testing worst case of size 6
## 1.7.0
vecperf.bench=> (def v [0 1 2 3 4 5])
#'vecperf.bench/v
vecperf.bench=> (quick-bench (reduce + 0 v))
WARNING: Final GC required 1.508801076780115 % of runtime
WARNING: Final GC required 13.47335649374595 % of runtime
Evaluation count : 11114412 in 6 samples of 1852402 calls.
@puredanger
puredanger / gist:40dd3ec22fdb5836d1eb
Created December 18, 2014 15:13
Disassembled code
This file has been truncated, but you can view the full file.
Compiled from "eclipse.clj"
public final class ccw.eclipse$goto_editor_line extends clojure.lang.AFunction {
public static final clojure.lang.Var const__0;
public static final clojure.lang.Var const__1;
public static final clojure.lang.Keyword const__2;
public static final clojure.lang.Keyword const__3;
@puredanger
puredanger / MultiFn-after.java
Last active August 29, 2015 14:11
MultiFn.findAndCacheBestMethod()
private IFn findAndCacheBestMethod(Object dispatchVal) {
rw.readLock().lock();
Object bestValue; // remember the best match IFn
IPersistentMap mt = methodTable;
IPersistentMap pt = preferTable;
Object ch = cachedHierarchy;
try
{
Map.Entry bestEntry = null;
for(Object o : getMethodTable())
@puredanger
puredanger / breezy.clj
Last active August 29, 2015 14:05 — forked from quephird/breezy.clj
Added type hints I suspect would make math faster here. Just eyeballing, so not sure if it's all right. Normally I would check the bytecode to look for boxing as well.
(ns fun-with-quil.breezy
(:use quil.core))
(set! *unchecked-math* true)
(def ^:constant screen-w 1920)
(def ^:constant screen-h 1080)
(defn r ^double [^long x ^long y]
(loop [k 0 i 0.0 j 0.0)]
(defn bar-chart-from-ranges-by-name
[data step-size]
{:pre [(not (nil? data))
(not (empty? data))
(> step-size 0)]}
(let [enc-begin (apply min (map first (vals data)))
enc-end (apply max (map second (vals data)))
enc-length (- enc-end enc-begin)
record-list (->> data
(map (fn [[k [b e]]]
@puredanger
puredanger / gist:7818026
Created December 6, 2013 03:18
safe rm
function rm () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
@puredanger
puredanger / responses.csv
Created December 2, 2013 05:37
Categorized responses from the Clojure/ClojureScript survey
Respondent ID Text Category Sub
61448432 Local Adoption. The community is very much concentrated in the US, with the exception of London. In the rest of Europe, not so much. In Belgium we hardly get 6 to 10 people joining a meetup. You see it in conferences too: Clojure presence is much higher at US conferences. adoption
61454845 Needs enterprise uptake and buy-in. adoption
61455773 It's a fairly insular community. adoption
61463826 In Japan... * Very little developer use with clojure. * it is too hard to find clojure developer. * it is too hard to find clojure documents for **non-lisp** programmer (I was non-lisp programmer before use clojure, but I am joyful **lisp style** programming with Clojure). adoption
61506717 Not mature enough language yet to be mainstream in corporate datacenters who think .NET is all you need. adoption
@puredanger
puredanger / gist:6250711
Created August 16, 2013 15:05
bash replacement for rm to prevent shooting yourself in the face.
function rm () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
@puredanger
puredanger / rps.clj
Created July 10, 2013 12:29
Rock Paper Scissors with core.async
(require 'clojure.core.async :refer :all)
(def MOVES [:rock :paper :scissors])
(def BEATS {:rock :scissors, :paper :rock, :scissors :paper})
(defn rand-player
"Create a named player and return a channel to report moves."
[name]
(let [out (chan)]
(go (while true (>! out [name (rand-nth MOVES)])))
(defn mapmap
"Apply kf and vf to a sequence, s, and produce a map of (kf %) to (vf %)."
([vf s]
(mapmap identity vf s))
([kf vf s]
(zipmap (map kf s)
(map vf s))))
(defn mapmapmap
"Apply kf and vf to the keys and vals of a map and zip the results."