Skip to content

Instantly share code, notes, and snippets.

Avatar
🌊
Focusing

Ben Kamphaus benkamphaus

🌊
Focusing
View GitHub Profile
@benkamphaus
benkamphaus / streaming-revenue.ipynb
Last active Feb 8, 2020
Analysis of my streaming revenue
View streaming-revenue.ipynb
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 Oct 6, 2017
Group all facts from a history DB for an entity in Datomic by transaction, using sorted map to order.
View e_tx_history.clj
(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 Jan 17, 2017
Use Python to dump a variable in a mat file into a numpy format delimited text file
View matimport.py
# 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 Nov 17, 2016
Find narcissistic numbers in Clojure (non-optimized)
View narcissist.clj
(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
How to use skimage glcm routines to create a glcm image.
View glcm_image.py
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 Apr 22, 2016
Find and retract orphans in Datomic
View not_unique.clj
(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 Mar 18, 2016
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.
View README.md

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 Mar 12, 2016
Look up a transaction by its uuid (will match uuid in logs)
View lookup-tx-by-uuid.clj
(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 Oct 26, 2015
Example of reified references as components of an entity
View membership.clj
(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 Aug 6, 2015
Datomic: chaining with to explore a prospective sequence of transactions, fairly dorky schema example
View with-bonanza.clj
(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