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 / README.md
Last active December 16, 2015 05:08
Cognician's new architecture with Clojure and Datomic: Notes
@robert-stuttaford
robert-stuttaford / with.clj
Last active December 19, 2015 07:09
Using Datomic's d/with to query a database as though some transaction had been committed, before actually committing it!
(def conn (d/conn some-uri))
(def some-id 12345)
(defn get-v [db] (ffirst (d/q '[:find ?v :in $ ?e :where [?e :some/attribute ?v]] db some-id)))
(get-v (d/db conn))
;; => :some-value
(def tx [[:db/retract some-id :some/attribute :some-value]
@robert-stuttaford
robert-stuttaford / web-session-tx-fn.clj
Created July 3, 2013 11:33
using database functions to avoid race conditions between multiple webservers
(defn start-session!
[]
;; put-value! talks to ring's sessions dsl
(put-value! :session-uuid (db/new-uuid)))
(defn uuid
[]
;; get-value talks to ring's sessions dsl
(get-value :session-uuid))
Check out README.md to get started editing Clojure with Emacs.
@robert-stuttaford
robert-stuttaford / notes.md
Last active December 24, 2015 21:29
Gain massive leverage in your tech stack with Clojure: Notes
@robert-stuttaford
robert-stuttaford / notes.md
Last active August 29, 2015 13:56
Immutable data...base? Notes
@robert-stuttaford
robert-stuttaford / start.cljs
Created August 21, 2014 13:07
Nicely grouped transaction logging in JS Console for Om apps
(ns app
(:require [om.core :as om :include-macros true]))
(defn log-tx [tx-data root-cursor]
(let [{:keys [path old-value new-value]} tx-data
c js/console]
(doto c (.group (str "TRANSACTION " path)) (.groupCollapsed "OLD"))
(prn (pr-str old-value))
(doto c (.groupEnd) (.group "NEW"))
(prn (pr-str new-value))
@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