Skip to content

Instantly share code, notes, and snippets.

@samroberton
samroberton / build.boot
Created April 11, 2016 11:56
My build.boot's dev task
(deftask dev
"Build and run development mode."
[i ios bool "Flag to enable iOS builds."]
(comp
(environ/environ :env {})
(watch)
(server-with-repl :port 7888)
@samroberton
samroberton / gist:d72cedaf225526d9007a
Last active February 25, 2021 07:10
Database 'unjoin'
(defn unjoin
"Given a seq `rows` as retrieved from a database select involving a join,
return a vector of nested entities, where the top-level entities have keys
`parent-keys`, plus a key for each key of `child-map`, where the value for
that key is a vector of values specified by the value in `child-map`.
Where the value in `child-map` is a simple keyword, the resulting vector will
contain the corresponding values for that keyword in `rows`.
Eg (unjoin [{:id 1, :a :foo} {:id 1, :a :bar}] [:id] {:vals :a}) =>
(defn expensive-fn [x]
(.log js/console (str "I ran (with value " x ")"))
(+ x 1))
(defn my-memoize [f]
(let [results (atom {})]
(fn [farg]
(or (get @results farg)