Skip to content

Instantly share code, notes, and snippets.

mydate <- strptime('Mon Dec 09 2019 13:35:10 GMT-0700',
format='%a %b %d %Y %H:%M:%S GMT%z')
(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"})
;; 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))
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
), joined_bar AS (
INSERT INTO bar(x) SELECT resource->'id' FROM inserted
) SELECT resource FROM inserted;
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
dadair-ca /
Created September 27, 2016 01:55
Clojure postgresql enum type conversion

Given an enum type e_role, being represented in clojure-land as a string, use the enum in a query and typecast inside it.

Note the ?::e_role:

INSERT INTO accounts (account_id, email, password, account_role)
       VALUES (DEFAULT, :email, :password, ?::e_role);

Use positional arguments for the enum(s) (note the :? [..]):

--- jwt ---
Starting HTTP server on port nil
{:hide-errors duct.middleware.errors/wrap-hide-errors,
:not-found duct.middleware.not-found/wrap-not-found,
:ring-json-response ring.middleware.json/wrap-json-response,
:ring-json-body ring.middleware.json/wrap-json-body},
FROM clojure
RUN mkdir -p /app
COPY ./dev /app/dev
COPY ./profiles.clj /app/profiles.clj
COPY ./project.clj /app/project.clj
COPY ./resources /app/resources
COPY ./src /app/src
dadair-ca / register.clj
Created September 5, 2015 21:54
(defn- register
[db mailer email password]
(if (users/valid? email password)
(if (users/taken? db email)
(response/bad-request {:errors [{:message "That email is taken."}]})
(do (users/do-create! db email password)
(users/notify mailer email activate-subject activate-text)
(response/ok (auth/authenticate email))))
(response/bad-request {:errors [{:message errors/invalid-creds}]})))
;; handlers
(defn- login
"Verifies that the user credentials are valid and returns a token
that can be used for future requests to secure resources."
[{{username :username} :body}]
(let [auth (authenticate username)]
(response/ok auth)))