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 with-timeout [seconds & body] | |
`(let [f# (future ~@body)] | |
(try | |
(.get f# ~seconds java.util.concurrent.TimeUnit/SECONDS) | |
(catch java.util.concurrent.TimeoutException e# | |
(do (future-cancel f#) nil))))) |
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 relate [& pairs] | |
(assert (even? (count pairs)) "relate requires an even number of arguments") | |
(->> pairs | |
(partition 2) | |
(map (fn [[k vs]] (map #(hash-map k %) vs))) | |
(apply map merge))) | |
(defn matches-specmap? [specmap m] | |
(reduce-kv |
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 spit-url [content] | |
(let [blob (js/Blob. (js/Array. content) {:type "text/plain;charset=utf-8"})] | |
(.createObjectURL js/URL blob))) |
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
const selectKeys = (m, keys) => { | |
return keys.reduce((acc, k) => { | |
acc[k] = m[k]; | |
return acc; | |
}, {}); | |
} | |
const invertMap = (m) => | |
Object.keys(m).reduce((acc, k) => { | |
acc[m[k]] = k; |
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
// | |
// Usage | |
// | |
// where before you might've had: | |
// const selection = parent.selectAll('li').data(data, keyFn) | |
// | |
// you now have: | |
const selection = diff(parent.selectAll('li'), data, keyFn) |
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
(require '[datomic.api :as d]) | |
(def uri "datomic:mem://policing") | |
(d/create-database uri) | |
(def conn (d/connect uri)) | |
;; We are managing classified documents. | |
(def schema | |
[{:db/ident :level/rank |
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
{:deps | |
{org.clojure/clojure {:mvn/version "1.9.0"} | |
com.datomic/datomic-free {:mvn/version "0.9.5697"}}} |
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
;; LWW Register | |
;; https://speakerdeck.com/ept/data-structures-as-queries-expressing-crdts-using-datalog?slide=15 | |
(def schema | |
{:assign/time {:db/valueType :Number} | |
:assign/key {:db/valueType :Number} | |
:assign/value {:db/valueType :Number}}) | |
(def rules | |
'[[(older ?t1 ?key) |
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
;; RGA | |
;; https://speakerdeck.com/ept/data-structures-as-queries-expressing-crdts-using-datalog?slide=22 | |
(def schema | |
{:id/node {:db/valueType :Number} | |
:id/ctr {:db/valueType :Number} | |
:insert/id {:db/valueType :Eid} | |
:insert/parent {:db/valueType :Eid} | |
:assign/id {:db/valueType :Eid} | |
:assign/elem {:db/valueType :Eid} |
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
(def encode-symbol (memoize (fn [sym] (clojure.lang.RT/nextID)))) |
OlderNewer