Skip to content

Instantly share code, notes, and snippets.

View stuarthalloway's full-sized avatar

Stuart Halloway stuarthalloway

View GitHub Profile
@stuarthalloway
stuarthalloway / how-many-datoms.clj
Created February 25, 2014 12:28
How many datoms did it make?
(require
'[datomic.api :as d])
(defn how-many-datoms-did-tx-make?
"Return the number of datoms created by transaction at
time t, defaulting t to the most recent transaction."
([conn] (how-many-datoms-did-tx-make? conn (-> conn d/db d/basis-t)))
([conn t]
(some-> (d/log conn) (d/tx-range t nil) first :data count)))
@stuarthalloway
stuarthalloway / interactive-query-dev.clj
Created March 5, 2015 20:15
Interactive Development of a Function Used in Query
(def zap (partial + 1))
(d/q '[:find ?b
:in ?a
:where [(user/zap ?a) ?b]]
1)
;; #{[2]}
(def zap (partial + 2))
(require '[datomic.api :as d])
(defn entity-summary
"Returns a map with
:eavt vector of all eavt history datoms with eid
:log vector of all log entries containing those datoms"
[conn eid]
(let [log (d/log conn)
db (d/db conn)
hist (d/history db)
@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
@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 / 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])
;; licensed like Clojure, copyright 2010 by Stuart Halloway
(ns
#^{:author "Stuart Halloway"
:doc "Protocols for type-aware collection functions"}
clojure.contrib.collections
(:import [java.util ArrayList Collection]))
(declare slice do-slice)
;; Copyright 2010 Relevance, Inc. Same license as Clojure http://clojure.org. You know the drill.
(ns clojure.core.protocols
(:refer-clojure :exclude [reduce nth count]))
#_(def array-classes
(map
#(Class/forName %)
["[Ljava.lang.Object;"
"[B" "[F" "[I" "[D" "[Z" "[J" "[C"]))
(deftest various-beans-are-readable
(testing "that all java.lang beans can be read without error"
(doseq [mb (jmx/mbean-names "*:*")]
(jmx/mbean mb))))
; response to http://toinfinity.wordpress.com/2010/05/01/does-groovy-know-you-are-seeing-clojure
; tell the gnomes! phase two is (map - closing-prices)!
; prior to 1.2, reductions is in clojure.contrib.seq-utils
(->> (reductions min closing-prices) ;; lowest prices at each point
(map - closing-prices) ;; possible profit at each point
(apply max)) ;; profit!