Skip to content

Instantly share code, notes, and snippets.

View benkamphaus's full-sized avatar
🌊
Focusing

Ben Kamphaus benkamphaus

🌊
Focusing
View GitHub Profile
@benkamphaus
benkamphaus / streaming-revenue.ipynb
Last active February 8, 2020 23:48
Analysis of my streaming revenue
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@benkamphaus
benkamphaus / e_tx_history.clj
Created October 6, 2017 15:54
Group all facts from a history DB for an entity in Datomic by transaction, using sorted map to order.
(require '[datomic.api :as d])
;; for a particular entity, find it's entire tx history
(defn e->tx-history [db ent-id]
(->> (d/datoms (d/history db) :eavt ent-id)
(map (fn [[e a v tx assert]]
[e
(-> db (d/pull '[:db/ident] a) :db/ident)
v
tx
@benkamphaus
benkamphaus / matimport.py
Created January 17, 2017 22:01
Use Python to dump a variable in a mat file into a numpy format delimited text file
# requires scipy and numpy:
# e.g., with:
# pip install scipy numpy
import sys
import scipy.io as sio
from numpy import savetxt
filein = sys.argv[1]
fileout = sys.argv[2]
arr_dict = sio.loadmat(filein)
@benkamphaus
benkamphaus / narcissist.clj
Created November 17, 2016 15:18
Find narcissistic numbers in Clojure (non-optimized)
(defn narcissistic?
"Returns true if n with m digits is equal to each digit in n to the
m exponent."
[n]
(let [digits (map #(Character/digit % 10) (str n))
n-digits (count digits)
exps (map #(Math/pow % n-digits) digits)]
(== n (apply + exps))))
(take 10 (filter narcissistic? (iterate inc 10)))
@benkamphaus
benkamphaus / glcm_image.py
Created May 5, 2016 04:55
How to use skimage glcm routines to create a glcm image.
import numpy as np
import skimage
from skimage.feature import greycomatrix, greycoprops
def glcm_image(img, measure="dissimilarity"):
"""TODO: allow different window sizes by parameterizing 3, 4. Also should
parameterize direction vector [1] [0]"""
texture = np.zeros_like(sub)
# quadratic looping in python w/o vectorized routine, yuck!
@benkamphaus
benkamphaus / not_unique.clj
Created April 22, 2016 14:09
Find and retract orphans in Datomic
(ns datomic-manual-tests.not-unique
(:require [datomic.api :as d]))
(def db-uri "datomic:mem://not-unique")
(d/create-database db-uri)
(def conn (d/connect db-uri))
(def schema
[{:db/id (d/tempid :db.part/db)
:db/ident :parent/child
@benkamphaus
benkamphaus / README.md
Last active June 28, 2022 16:42
High throughput Datomic Transactor AMI config -- creds/region info removed, only perf related fields. For typical deployments you should prefer the defaults -- these settings are for very high throughput systems.

What is this gist?

This is just a snapshot of what a high throughput Datomic transactor config looks like (with credentials/region, etc. settings elided).

I do not recommend cargo culting these settings for lower throughput systems. In those cases you should prefer the defaults.

Please refer to the capacity planning docs for a more nuanced understanding.

Warnings out of the way, here is how to use these reference settings:

@benkamphaus
benkamphaus / lookup-tx-by-uuid.clj
Last active March 12, 2016 14:37
Look up a transaction by its uuid (will match uuid in logs)
(require '[datomic.api :as d])
(defn tx-maps [log start]
(into [] (map #(into {} %) (d/tx-range log start nil))))
(defn txid-match? [uuid]
(fn [tx-map]
(= uuid (:id tx-map))))
(defn lookup-tx [log uuid-val]
@benkamphaus
benkamphaus / membership.clj
Created October 26, 2015 23:20
Example of reified references as components of an entity
(ns datomic-manual-tests.membership
(:require [datomic.api :as d]))
(def db-uri "datomic:mem://memership")
(d/create-database db-uri)
(def conn (d/connect db-uri))
(def schema
[{:db/id (d/tempid :db.part/db)
:db/ident :person/name
@benkamphaus
benkamphaus / with-bonanza.clj
Created August 6, 2015 21:05
Datomic: chaining with to explore a prospective sequence of transactions, fairly dorky schema example
(ns datomic-manual-tests.with-bonanza
(:require [datomic.api :as d]))
(def db-uri "datomic:mem://people")
(d/create-database db-uri)
(def conn (d/connect db-uri))
(def schema
[{:db/id (d/tempid :db.part/db)
:db/ident :person/age