Skip to content

Instantly share code, notes, and snippets.

View codonnell's full-sized avatar

Chris O'Donnell codonnell

View GitHub Profile
@codonnell
codonnell / Dockerfile
Created June 27, 2020 12:20
Flyway dockerfile using DATABASE_URL
FROM flyway/flyway:6.4.2
COPY migrations /flyway/sql
COPY parse-url.sh /parse-url.sh
USER root
RUN apt update && apt -y install --no-install-recommends curl
@codonnell
codonnell / core.clj
Created June 22, 2020 11:32
Honeysql + clojure.java.jdbc returning example
(ns returning-example.core
(:require [clojure.java.jdbc :as jdbc]
[honeysql.core :as sql]
[honeysql.format]
[honeysql-postgres.format]))
(def db-spec
{:dbtype "postgresql"
:dbname "postgres"
:user "postgres"
@codonnell
codonnell / gift_list.cljs
Created April 18, 2020 13:26
Fulcro form example
(ns rocks.mygiftlist.ui.gift-list
(:require
[com.fulcrologic.fulcro.algorithms.form-state :as fs]
[com.fulcrologic.fulcro.algorithms.merge :as merge]
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]
[com.fulcrologic.fulcro.dom :as dom]
[com.fulcrologic.fulcro.mutations :as m]
[com.fulcrologic.semantic-ui.elements.button.ui-button :refer [ui-button]]
[com.fulcrologic.semantic-ui.collections.form.ui-form :refer [ui-form]]
@codonnell
codonnell / create_gift.cljs
Last active April 7, 2020 11:37
Error handling with fulcro and pathom
;; Example error-action
(error-action [{:keys [state result] :as env}]
(let [message (get-in env [:result :body `create-gift ::p/error ::anom/message])]
(swap! state
#(-> %
(assoc-in [::gift/id id :ui/submitting] false)
(assoc-in [:component/id :flash-message] #:ui{:active true
:message message
:type "negative"})))))
@codonnell
codonnell / demo.cljs
Created March 19, 2019 19:29
POC Fulcro GraphQL Snippet
(fp/defsc GiftList
[this {:gql.gift/keys [id name]}]
{:ident [:gql.gift/id :gql.gift/id]
:query [:gql.gift/id :gql.gift/name]}
(js/console.log {:gift [id name]})
(dom/div "Gift list " id ": " name))
(def ui-gift-list (fp/factory GiftList {:keyfn :gql.gift/id}))
(fp/defsc GiftListDemo
@codonnell
codonnell / hugsql-wrapper.clj
Created June 20, 2018 00:46
Working but not DRY macro
(defn wrapped-query [from-db to-db query]
(fn [db m]
(->> m to-db (query db) from-db)))
(defn def-wrapped-query* [from-db to-db query]
(let [{:keys [result] :as query-meta} (meta (resolve query))]
(case result
(:1 :one) `(def ~query ~(with-meta
(wrapped-query @(resolve from-db) @(resolve to-db) @(resolve query))
query-meta))
@codonnell
codonnell / kata.clj
Last active January 7, 2018 21:21
code kata parsing
(ns kata
(:require [clojure.string :as str]
[clojure.pprint :refer [pprint]]
[net.cgrand.xforms :as xf))
(def example-input "Los Angeles Clippers 104 Dallas Mavericks 88,New York Knicks 101 Atlanta Hawks 112,Indiana Pacers 103 Memphis Grizzlies 112, Los Angeles Clippers 100 Boston Celtics 12")
(defn score? [s]
(try (Integer. s)
true