Skip to content

Instantly share code, notes, and snippets.

@comnik
comnik / morgana-relations.clj
Created November 14, 2018 00:03
Generating data relationships with datamorgana
(s/def :db/id (s/with-gen number? #(gen/fmap (fn [_] (clojure.lang.RT/nextID)) (gen/int))))
(s/def :entity/name (s/and string? #(< 3 (count %) 10)))
(s/def :entity/shareholder :db/id)
(s/def :person/id (s/with-gen string? #(s/gen #{"Alice" "Bob" "Eve" "Mabel" "Dipper"})))
(s/def :person/alias :db/id)
(s/def :company/name (s/with-gen string? #(s/gen #{"Alice" "Bob" "Eve" "Mabel" "Dipper"})))
(s/def :company/subsidiary :db/id)
@comnik
comnik / btset.cljc
Created November 16, 2018 20:01
Unary Leapfrog on datascript.btset
;; the BTset namespace needs has to be extended by the
;; following helper
(defn iter-seek
"Returns iterator for all X where key-from <= X."
[^Iter iter key-from]
(let [path (-seek (.-set iter) key-from)]
(when-not (neg? path)
(Iter. (.-set iter) path (.-right iter) (keys-for (.-set iter) path) (path-get path 0)))))
@comnik
comnik / shipping.rs
Last active April 16, 2019 06:52
The shipping puzzle (https://kevinlynagh.com/notes/shipping-puzzle/) in Differential Dataflow
#[macro_use]
extern crate abomonation_derive;
extern crate abomonation;
extern crate timely;
extern crate differential_dataflow;
use std::fs::File;
use std::io::{BufRead,BufReader};
use timely::dataflow::*;
<script src="https://github.com/tonsky/datascript/releases/download/0.18.2/datascript-0.18.2.min.js"></script>
<script type="text/javascript">
const d = datascript;
const schema = {
"db/ident": {":db/unique": ":db.unique/identity"},
"operator/name": {":db/cardinality": ":db.cardinality/one"},
"operator/address": {":db/unique": ":db.unique/identity"},