Skip to content

Instantly share code, notes, and snippets.

Avatar

David Adair dadair-ca

View GitHub Profile
View R-parse-JS-date.R
mydate <- strptime('Mon Dec 09 2019 13:35:10 GMT-0700',
format='%a %b %d %Y %H:%M:%S GMT%z')
View logging_context.clj
(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"})
View clojure_decorator.clj
;; 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))
View fhirbase-CTEs.sql
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;
@dadair-ca
dadair-ca / example.clj
Last active Oct 2, 2016
core async processing improvements
View example.clj
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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
dadair-ca / description.md
Created Sep 27, 2016
Clojure postgresql enum type conversion
View description.md

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 :? [..]):

View console output
--- jwt ---
nil
Starting HTTP server on port nil
{:app
{:middleware
{:functions
{: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},
View Dockerfile-dev
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
View register.clj
(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}]})))
View clojure-closure-help.clj
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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)))