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 / scratch.clj
Created May 26, 2015 19:12
Testing behaviour of Datomic's :db/isComponent
(ns scratch
(:require [datomic.api :as d]))
(def u "datomic:mem://component-test")
(d/delete-database u)
(d/create-database u)
(def c (d/connect u))
@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
(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
(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])
15-Aug-19 22:29:18 MacBook-Pro.local WARN [onyx.peer.task-lifecycle] -
java.lang.Thread.run Thread.java: 745
java.util.concurrent.ThreadPoolExecutor$Worker.run ThreadPoolExecutor.java: 617
java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java: 1142
...
clojure.core.async/thread-call/fn async.clj: 405
onyx.peer.task-lifecycle.TaskLifeCycle/fn task_lifecycle.clj: 706
onyx.peer.task-lifecycle/run-task-lifecycle task_lifecycle.clj: 431
onyx.peer.task-lifecycle/write-batch task_lifecycle.clj: 304
onyx.plugin.datomic.DatomicLogInput/write-batch datomic.clj: 255
@robert-stuttaford
robert-stuttaford / keys_with_and_question.clj
Last active June 16, 2016 14:03
Clojure core.spec question: composing s/keys with s/and
;; using Clojure 1.9-alpha7
(ns keys-with-and-question
(:require [clojure.spec :as s]
[clojure.spec.gen :as gen]))
(s/def ::id string?)
(s/def ::active? boolean?)
(s/def ::extra int?)
(s/def ::base (s/keys :req-un [::id] :opt-un [::active?]))
@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 / fira-code.el
Created August 25, 2016 15:06
FiraCode + Emacs
(when (window-system)
(set-default-font "Fira Code"))
(let ((alist '((33 . ".\\(?:\\(?:==\\|!!\\)\\|[!=]\\)")
(35 . ".\\(?:###\\|##\\|_(\\|[#(?[_{]\\)")
(36 . ".\\(?:>\\)")
(37 . ".\\(?:\\(?:%%\\)\\|%\\)")
(38 . ".\\(?:\\(?:&&\\)\\|&\\)")
(42 . ".\\(?:\\(?:\\*\\*/\\)\\|\\(?:\\*[*/]\\)\\|[*/>]\\)")
(43 . ".\\(?:\\(?:\\+\\+\\)\\|[+>]\\)")
(45 . ".\\(?:\\(?:-[>-]\\|<<\\|>>\\)\\|[<>}~-]\\)")
@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)
@robert-stuttaford
robert-stuttaford / circle.env.yml
Last active September 21, 2016 03:22
Set a bunch of env vars on many CircleCI projects via API
AWS_ACCESS_KEY_ID: ABCDEFGHIJKLMNOPQRSTUVWXYZ
AWS_SECRET_ACCESS_KEY: supercalifragilisticexpialidocious
# more: values
# go: here