The past is a grotesque animal
And in its eyes you see
How completely wrong you can be
-- Of Montreal
def edn-string | |
(schema/named schema/Any "Should be a valid EDN string")) | |
(defn saved-search-matcher [schema] | |
({schema/Num #(try (Double/parseDouble %) (catch Exception _ %)) | |
edn-string #(try (read-string %) (catch Exception _ %))} schema)) | |
(def search-criteria | |
(schema/both | |
edn-string |
;; Datomic example code | |
(use '[datomic.api :only (db q) :as d]) | |
;; ?answer binds a scalar | |
(q '[:find ?answer :in ?answer] | |
42) | |
;; of course you can bind more than one of anything | |
(q '[:find ?last ?first :in ?last ?first] | |
"Doe" "John") |
(require '[clojure.data.generators :as gen]) | |
(defn weighted-interleave | |
"Given a map of infinite sequences to weights, it produces a new | |
infinite sequence where each element is selected randomly (according | |
to the weights) from one of the passed sequences. The sequences are | |
only advanced when the element is actually selected. | |
Example: |
> (reduce-kv (fn [m k v] (assoc m (str k) v)) {} {:a 1 :b 2}) | |
{":a" 1, ":b" 2} |
;;map lag with multiple accumulators | |
(defn map-lag | |
"fun is a function with arity equal to the number of accumulators | |
+1. It's expected to return a vector of the same length as its | |
arity. | |
accs is a vector of initial states for all the | |
accumulators. | |
coll is the collection to be processed." |
(reduce | |
(fn [{:keys [odd even]} datum] | |
(if (odd? datum) | |
{:odd (conj odd datum) | |
:even even} | |
{:odd odd | |
:even (conj even datum)})) | |
{:odd [] | |
:even []} | |
(range 20)) |
(defn prewalkseq | |
"Like prewalk but only for seqs and uses zippers." | |
[f s] | |
(loop [z (zip/seq-zip s)] | |
(if (zip/end? z) | |
(zip/root z) | |
(recur (zip/next (zip/replace z (f (zip/node z)))))))) | |
;;replace zip/seq-zip with zip/vector-zip for vectors |
alias ipext='curl -s http://checkip.dyndns.org/ | grep -o [0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9]*' |
;;see http://stackoverflow.com/questions/16215169/clojure-csv-with-escaped-comma | |
(require '[instaparse.core :as insta]) | |
((insta/parser | |
"quoted-field = <'\\\"'> (#'[^\"\\\\]+' | escaped-char)* <'\\\"'> | |
<escaped-char> = #'\\\\.'") "\"hello\\\" world\"") | |
;;and to parse comments like /** this is a test */ | |
;;http://stackoverflow.com/questions/11125459/java-regex-negative-lookahead |