Skip to content

Instantly share code, notes, and snippets.

View robert-stuttaford's full-sized avatar
💭
Clojure!

Robert Stuttaford robert-stuttaford

💭
Clojure!
View GitHub Profile
@robert-stuttaford
robert-stuttaford / notes.md
Last active March 18, 2024 13:52
Datomic 0.9.5927 observations and questions

Query basics

{:db/ident       :meta/tag
 :db/valueType   :db.type/tuple
 :db/tupleAttrs  [:meta/tag-namespace :meta/tag-key :meta/tag-value] ;; all unique strings
 :db/cardinality :db.cardinality/one
 :db/unique      :db.unique/identity}

Then

@robert-stuttaford
robert-stuttaford / throughput-accounting.md
Last active January 4, 2022 22:38
Throughput accounting for hybrid SaaS + consultancy

Throughput Accounting

https://chronologist.com/blog/2012-07-27/theory-of-constraints-and-software-engineering/

Measures

  • Throughput: TE is the rate of cash generated through delivery of working code into production. It is computed as sales price minus direct costs, such as packaging, delivery, installation, training, support, and networking.
  • Investment: I is all money invested in software production systems plus money spent to obtain ideas for client-valued functionality. This does not apply to time spent by staff (that's Operating Expense). It does apply to the money spent on by-the-hour contractors.
  • Operating Expense: OE is all money spent to produce working code from ideas. It is primarily direct labor of software engineers, but it also includes selling, general, and administrative costs. So, our fixed overheads.
@robert-stuttaford
robert-stuttaford / translate.clj
Last active March 24, 2019 20:44
Language translations for Datomic entities with fallback to base entity
(ns cognician.db.translate
(:require [datomic.api :as d])
(:import [clojure.lang MapEntry]
[datomic.query EntityMap]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Language
(def default-language :en-GB)
(ns scratch
(:require [clojure.spec.alpha :as s]))
(def cards
[{:suite :diamonds
:value :king}
{:suite :clubs
:value 4}])
(def cards-sorted
@robert-stuttaford
robert-stuttaford / build.clj
Last active August 1, 2018 14:18
Basic nREPL / cljs compile / cljs repl / figwheel script for use with clj cli command: `clj build.clj TASK`
(require '[cljs.build.api :as api]
'[clojure.string :as string]
'[figwheel-sidecar.repl-api :as figwheel]
'[figwheel-sidecar.components.nrepl-server :as figwheel.nrepl])
(def source-dir "src")
(def compiler-config
{:main 'app.main
:output-to "target/app.js"
@robert-stuttaford
robert-stuttaford / magic-the-gathering-card-spec.clj
Created June 17, 2016 06:49
Noodling around with core.spec, modelling M:tG card data
(ns magic-the-gathering-card-spec
(:require [clojure.spec :as s]
[clojure.spec.gen :as gen]))
(s/def ::pos-int (s/and int? (complement neg?)))
(s/def ::set string?)
(s/def ::set-number ::pos-int)
(s/def ::artist string?)
@robert-stuttaford
robert-stuttaford / datomic.clj
Last active April 27, 2018 15:10
Handy protocols for working with Datomic
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Connection
(defprotocol DatomicConnection
(as-conn [_]))
(extend-protocol DatomicConnection
datomic.Connection
(as-conn [c] c)
datomic.db.Db
(ns onyx-tx-report-queue
(:require [clojure.core.async :refer [>!! alts!! chan close! put! thread]]
[clojure.tools.logging :as log]
;; :all so clj-refactor doesn't remove it:
[onyx.plugin.core-async :refer :all]
[datomic.api :as d])
(:import [java.util.concurrent TimeUnit]))
(defn prepare-datom [db [e a v tx added]]
[e (d/ident db a) v tx added])
(let [dt #(-> (clj-time.core/date-time 2015 % %2)
clj-time.coerce/to-date)
now (d/db (d/connect (db/database-uri :main)))]
[(db/conn (db/database-uri :main))
(vec
(for [db [now ;; 29th July 2015
(-> now
(d/since (dt 2 1))) ;; 1st Feb 2015
(-> now
(d/as-of (dt 2 1))) ;; 1st Feb 2015
@robert-stuttaford
robert-stuttaford / config.edn
Last active May 1, 2017 07:07
Using Onyx with Trapperkeeper
{:environment :production
:global {:logging-config "./logback.xml"}
:onyx {:job-scheduler :onyx.job-scheduler/balanced
:task-scheduler :onyx.task-scheduler/balanced
:peer-config {:onyx.messaging/impl :netty
:onyx.messaging/peer-port-range [40200 40220]
:onyx.messaging/peer-ports [40199]
:onyx.messaging/bind-addr "localhost"
:onyx.messaging/backpressure-strategy :high-restart-latency}
:peer-count 20