Skip to content

Instantly share code, notes, and snippets.

View llasram's full-sized avatar

Marshall Bockrath llasram

View GitHub Profile
@llasram
llasram / zwj.clj
Last active August 29, 2015 14:18 — forked from anonymous/zwj.clj
(let [f‍oo 1, foo 2] [f‍oo foo])
;; => [1 2]
@llasram
llasram / mapify.clj
Last active August 29, 2015 14:13 — forked from kindlychung/mapify.clj
(defn mapify
"Return a seq of maps like {:name \"Edward Cullen\" :glitter-index 10}"
[rows]
(let [headers (map (comp conversions headers->keywords) (first rows))]
(map (partial zipmap headers) (rest rows))))
@llasram
llasram / mean-sd.clj
Last active July 30, 2017 17:38 — forked from timvisher/-
(defn ^:private mean-sd-step
[[n m s] ^double x]
(let [n (long n), m (double m), s (double s)
n (inc n), d (- x m), m (+ m (/ d n)), s (+ s (* d (- x m)))]
[n m s]))
(defn mean-sd
"Calculate mean and (sample) standard-deviation of `vals`."
[vals]
(let [[n m s] (reduce mean-sd-step [0 0.0 0.0] vals)]
(defmacro make-servlet
"Call to generate a servlet class given the class name and a ring handler."
[servlet handler]
(let [servlet (name servlet), prefix (str servlet "-")]
`(do (println "Compiling Servlet" ~servlet)
(gen-class :name ~servlet
:prefix ~prefix
:extends javax.servlet.http.HttpServlet)
(s/defservice ~prefix ~handler))))
@llasram
llasram / gist:3251293
Created August 3, 2012 20:34 — forked from pbostrom/gist:3250162
Transaction side effects
(let [a (agent nil), q (ref []), x (ref 0)]
(defn run-side-effects [_]
(let [fs (dosync
(let [q' @q]
(ref-set q [])
q'))]
(doseq [f fs] (f))))
(defn alter-and-order-side-effects []
(dosync
(import '(java.io ByteArrayInputStream ByteArrayOutputStream
ObjectInputStream ObjectOutputStream))
(defmacro wtf
[]
(Boolean. false)) ;; note the lack of syntax-quote
---------
user=> (wtf)
@llasram
llasram / ex17-3.py
Created March 6, 2012 19:17 — forked from mattcmaddox/gist:1988368
Python the Hard Way exercise 17, extra credit 3
from sys import argv
from os.path import exists
script, from_file, to_file = argv
action = open(from_file)
(#(let
[s (fn !
([a] a)
([a & more] (for [x a y (apply ! more) :while (>= x y) :when (= x y)] x)))]
(first (apply s %&))) [1 2 100] [3 5 100] (range))
@llasram
llasram / deftest-org.clj
Created January 19, 2012 22:12 — forked from semperos/deftest-org.clj
deftest organization
(defn my-check [x]
(is (good? x))
(defn another-check [x]
(is (alright? x))
(def all-checks
[my-check another-check])
(defn run-checks [browser]