Skip to content

Instantly share code, notes, and snippets.

@dadair-ca
dadair-ca / example.clj
Last active October 2, 2016 19:52
core async processing improvements
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Forecast generation
(defn inst->forecasts [inst]
(for [r (range 1 25)]
[(c/to-sql-time (t/plus (without-minutes inst) (t/hours r))) (rand-int 50)]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Async
WITH inserted AS (
SELECT fhir_create_resource(:resource) AS resource -- should end up inserting into `encounter` table
), joined_foo AS (
INSERT INTO foo(x) SELECT resource->'id' FROM inserted
RETURNING *
), joined_bar AS (
INSERT INTO bar(x) SELECT resource->'id' FROM inserted
RETURNING *
) SELECT resource FROM inserted;
;; Let's say we have a function `foo`, that we want to decorate with logging:
(defn foo [x]
(inc x))
;; First, let's change the name to suggest an impl:
(defn foo* [x]
(inc x))
(defprotocol Logging
(log [logger data]))
(def ^:dynamic *logger*
(reify Logging
(log [this data]
(clojure.pprint/pprint data))))
(def request-data {::request-id 1 ::request-source "someone"})
mydate <- strptime('Mon Dec 09 2019 13:35:10 GMT-0700',
format='%a %b %d %Y %H:%M:%S GMT%z')