This file contains hidden or 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 when-lets [bindings & body] | |
| (reduce (fn [acc tstform] | |
| `(when-let ~tstform ~acc)) | |
| (cons 'do body) | |
| (reverse (map vec (partition 2 bindings))))) | |
| (when-lets [n (first sizes) | |
| s (seq coll)] | |
| (cons (take n coll) | |
| (partitions (next sizes) (drop n coll))))) |
This file contains hidden or 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 phase-fn | |
| ([argvec] identity) | |
| ([argvec subphase & left] | |
| `(fn [session# ~@argvec] | |
| (--> session# | |
| ~subphase | |
| ~@(when left | |
| [`((phase-fn ~argvec ~@left))]))))) |
This file contains hidden or 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 defratios | |
| "Defines two converter functions with num-expr being how many of a make up b. | |
| For example, there are 100 centimeters in a meter. To tell the program to make | |
| (centimeter->meter) and (meter->centimeter), use (defratios meter centimeters 100)" | |
| [a-symb b-symb num-expr] | |
| (and (every? #{clojure.lang.Symbol} | |
| (map type [a-symb b-symb])) | |
| (let [ab-symb (symbol (arr a-symb b-symb)) | |
| ba-symb (symbol (arr b-symb a-symb)) | |
| num (gensym "num-")] |
This file contains hidden or 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 alternates | |
| "Split coll into 'threads' subsequences (defaults to 2), feeding | |
| each alternately from the input sequence. Effectively the inverse of | |
| interleave: | |
| (alternates 3 (range 9)) | |
| ;=> ((0 3 6) (1 4 7) (2 5 8))" | |
| ([coll] (alternates 2 coll)) | |
| ([threads coll] | |
| (for [offset (range threads)] |
This file contains hidden or 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
| (ns use-opts.core | |
| (:use (clojopts core))) | |
| (clojopts "clojopts-test" | |
| ["-t" "myfile"] | |
| (no-arg time t "STOP TIME. USE WITH CAUTION")) |
This file contains hidden or 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 [plugins #{#_"dictionary" "lmgtfy" "google" "translate" "eball" "utils" "leet" "clojure" "login" "log" | |
| "weather" "brainfuck" "whatis" "shorturl" "haskell" | |
| "mail" "timer" "fortune" "rss" "title" "operator" "seen" "sed" "help" | |
| "load" "embedded" "karma" "ping" "debug"}] | |
| {:servers ["irc.freenode.net"] ; A list of servers. | |
| :prepends #{":"} ; The character you want for a prepend. Currently set to @ | |
| :dont-sed #{"tomoj" "hiredman"} | |
| :bitly-login "" ; Your bit.ly login. | |
| :bitly-key "" ; API key and login above needed for URL shortening. | |
| :wordnik-key "" ; API key needed for dictionary access. |
This file contains hidden or 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 largest-size [kfn l item] | |
| (if (empty? l) | |
| item | |
| (if (nil? item) | |
| (recur kfn (next l) (first l)) | |
| (let [f (first l)] | |
| (recur kfn | |
| (next l) | |
| (if (> (kfn f) (kfn item)) f item)))))) |
This file contains hidden or 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 process-urls [callback chunk-size stream] | |
| (let [mcurl (MCurl.)] | |
| (letfn [(add-handle | |
| [next-thunk] | |
| (when-let [[url cbdata] (next-thunk)] | |
| (.add mcurl (Curl. url inner-callback cbdata)))) | |
| (inner-callback | |
| [info content data] | |
| (add-handle #(or (apply callback args) | |
| (stream))))]) |
This file contains hidden or 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 update | |
| [m [& keys] f & args] | |
| (reduce (fn [m k] | |
| (update-in m [k] #(apply f % args))) | |
| m keys)) |
This file contains hidden or 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 routes | |
| "Calculates all the routes from [x y] to [0 0]. | |
| Routes move only down and left." | |
| [x y] | |
| ((fn routes* [queue] | |
| (lazy-seq | |
| (loop [queue queue] | |
| (when (pos? (count queue)) | |
| (let [[current-level [x y]] (peek queue) | |
| queue-left (pop queue) |