Skip to content

Instantly share code, notes, and snippets.

View stuarthalloway's full-sized avatar

Stuart Halloway stuarthalloway

View GitHub Profile
(require '[cognitect.transcriptor :refer (check!)])
(+ 1 2)
(check! pos-int?)
@stuarthalloway
stuarthalloway / clojure_spec_missing_piece.clj
Created March 17, 2017 01:11
Clojure spec's missing piece
;; clojure.spec's missing piece, work in progress
;; this is only halfway done, somebody else will need to do the other 95%
(require
'[clojure.spec :as s]
'[clojure.spec.test :as test])
(defn naive-english-explain
"Copy and paste this into your app. Figure out what it does by
trying it in production."
@stuarthalloway
stuarthalloway / errors_as_data.clj
Created March 16, 2017 17:27
Errors as data compose, error messages not so much
;; spec errors are data, and as such are composable with all the rest
;; of Clojure. The forms below show getting to an interesting part
;; of an error in a larger data structure, taking advantage of
;; edn-reading, pretty-printing, *print-length* and threading macro.
;; It is difficult to maintain the compositionality shown here
;; once you convert error data into e.g. ASCII art.
(require
'[clojure.edn :as edn]
(a/transduce
(comp
(halt-when error?)
(map ...)
(filter ...))
(completing ...)
accumulator
query)
@stuarthalloway
stuarthalloway / add_at.clj
Created August 17, 2016 12:44
add-at, take 1
;; non-working add-at
(require '[boot.core :as core]
'[boot.tmpdir :as tmpd]
'[clojure.java.io :as io])
(deftask add-at
"Like sift :add-*, but lets you make a dest path in fileset"
[r rolekey ROLEKEY kw "rolekey"
s source SOURCE file "source path in project"
d dest DEST file "dest path in fileset"]
(s/keys :req [::first-name
::last-name
::middle-initial])
(s/keys :req [::first-name
::last-name
::middle-initial]
:opt-un [::middle-name])
@stuarthalloway
stuarthalloway / log_size.clj
Created August 7, 2015 18:49
(Rough) total JVM memory size of the log
;; bin/run log_size.clj DB-URI t
;; Estimates the total in-memory size of all log entries from t to end of data.
;; Scans log from t to the end, so run against a backup instead of production if possible!
(require
'[clojure.edn :as edn]
'[clojure.pprint :as pp]
'[datomic.api :as d]
'[datomic.memory-size :as size])
@stuarthalloway
stuarthalloway / crosscheck_tx_instants.clj
Created August 7, 2015 18:48
Crosscheck db/txInstants in log and indexes
;; bin/run crosscheck_tx_instants.clj DB-URI t
;; This program walks the log to find txInstants
;; and then finds the same instants in the indexes.
;; Scans log from t to the end, so run against a backup instead of production if possible!
(require
'[clojure.edn :as edn]
'[clojure.pprint :as pp]
'[datomic.api :as d])
@stuarthalloway
stuarthalloway / log_as.clj
Created August 6, 2015 15:17
Log walk filtered to a single attribute
;; bin/run log_as.clj DB-URI t attr
;; This program walks the log extracting datoms about a particular attribute.
;; Reveals domain data, but only about that one attribute.
;; Scans log from t to the end, so run against a backup instead of production if possible!
(require
'[clojure.edn :as edn]
'[clojure.pprint :as pp]
'[datomic.api :as d])
@stuarthalloway
stuarthalloway / log_ts.clj
Created August 5, 2015 20:06
Information about Datomic log ts
;; This program walks the entire log extracting information about t
;; Does not reveal any domain data.
;; Scans entire log, so run against a backup instead of production if possible!
(require '[datomic.api :as d]
'[clojure.pprint :as pp])
(defn max-t
"Returns the maximum t mentioned in a collection of datoms"
[datoms]
(reduce