This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(#(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
from os.path import exists | |
script, from_file, to_file = argv | |
action = open(from_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '(java.io ByteArrayInputStream ByteArrayOutputStream | |
ObjectInputStream ObjectOutputStream)) | |
(defmacro wtf | |
[] | |
(Boolean. false)) ;; note the lack of syntax-quote | |
--------- | |
user=> (wtf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [foo 1, foo 2] [foo foo]) | |
;; => [1 2] |