Skip to content

Instantly share code, notes, and snippets.

@katox
katox / gist:d5817209aec78edb052f851c86e34f99
Created May 4, 2020 11:46
clojure.test helper function for Malli
(def conforming? 'conforming?)
(defmethod clojure.test/assert-expr 'conforming? [msg form]
;; (is (conforming? schema structure))
;; Asserts that evaluating structure conforms to the given malli schema
`(let [schema# ~(nth form 1)
structure# ~(nth form 2)]
(try (let [result# (m/validate schema# structure#)]
(if result#
(do-report {:type :pass, :message ~msg,
@katox
katox / smt.clj
Created September 28, 2019 18:34
From elegance to speed (Clojure version)
;;
;; http://johnj.com/from-elegance-to-speed.html
;;
;; The Clojure version
;; -------------------
(ns smt
(:require [net.cgrand.xforms :as x]
[criterium.core :as c :refer [quick-bench]]))
@katox
katox / gist:10732098
Created April 15, 2014 13:21
com.datomic/datomic-free "0.9.4707" -> "0.9.4714" incompatiblity
lein test
lein test omlab.db.user-test
lein test :only omlab.db.user-test/user-changes
ERROR in (user-changes) (datalog.clj:1148)
Uncaught exception, not in assertion.
expected: nil
actual: java.lang.Exception: processing rule: (q__10347 ?op ?e ?a ?v), message: processing clause: (ref-keyword ?e ?a ?v), message: processing rule: [ref-keyword ?e ?a ?v], message: processing clause: [?en :db/ident ?v], message: Cannot resolve key: $2a$10$Hfb7nFYC8s7f7gX5wxsOZ.YvoFe7NVyc4jvOwITNR4ZDLNGOCO8Ci
(defmacro bg
"Runs the body in a background thread.
Creates two vars, one named bg<N> and the other bg<N>'.
The first will eventually contain the result of the computation,
or any exception that is thrown.
The second is a map that prints with status & runtime information.
@katox
katox / gist:8865082
Last active July 20, 2018 10:25
Compare-and-set with datomic upsert
;; insert test case within project https://github.com/Datomic/day-of-datomic into 'lein repl'
(use '[datomic.api :only [q db] :as d])
(use 'clojure.pprint)
(def uri "datomic:mem://seattle")
(d/create-database uri)
(def conn (d/connect uri))
(def schema-tx (read-string (slurp "samples/seattle/seattle-schema.edn")))