Skip to content

Instantly share code, notes, and snippets.


Chris Thompson teaforthecat

  • Saint Paul, MN
View GitHub Profile
View content.clj
(ns how-to.content
(:require [interlope.core :as i]))
(defn format-for
" Returns a function for easy access to I18N content.
Take this closure and pass it around, puff puff pass
(let [f (format-for alerts :en)]
(f [:title] {:state-name \"MN\"}))"
[content-map lang state-abbrev]
View hardcoded_content.clj
(def state-specific-content
"Some states require just a little... extra."
{:en {
;; Alaska
:ak {:disclaimer "<p>Alaska will have an option to transmit absentee ballot applications electronically in 2020. You can request an absentee ballot application by electronic transmission until Monday, November 2, 2020. For more information, please visit <a href=\"\"></a></p>"}
;; California
:ca {:disclaimer "&nbsp;Conditional voter registration is a safety net for Californians who miss the deadline to register to vote or update their voter registration information. Voters can use the conditional voter registration process from the day after the deadline all the way through Election Day. Eligible citizens can go to their county election office or a designated satellite location to register and vote conditionally. These ballots will be processed once the county elections office
teaforthecat / gist:d250d355225133c57f1da2c3eb191616
Created Feb 11, 2019
lazy stream of kafka messages in clojure
View gist:d250d355225133c57f1da2c3eb191616
(defn message-stream
(message-stream c ()))
([c a]
(cons a
(message-stream c (seq (poll! c)))))))
View gist:d62e77063b8709fca71e56a7ce40bb3a
state (atom :continue)
;; state event new state
state-machine {:continue {:pause :paused
:halt :halting}
:paused {:resume :resuming
:halt :halting}
:resuming {:continue :continue}
:halting {:halt :halted}}
step-state (fn [transition]
teaforthecat / sql.clj
Created Mar 12, 2018
sql macro; finding a short path to named parameters
View sql.clj
(ns sql)
(defn sub-qmark [i form]
(if (keyword? form)
['? form] ;;todo need a stateful transducer
(defn params [body]
(map-indexed sub-qmark body))
teaforthecat / accumulate.clj
Last active Feb 19, 2018
fun with accumlating window transducer
View accumulate.clj
(defn accumulate
"If an input satisfies ACC-PRED, accumulate it with ACC-FN (defaults to merge)
All inputs will be passed on normally.
All accumulated inputs will be merged (using ACC-FN) to following inputs until RESET-PRED.
The input that satisfies RESET-PRED will receive the accumulated values and the input following it will receive none.
The default ACC-FN, `merge`, assumes a stream of maps"
([acc-pred reset-pred]
(accumulate acc-pred reset-pred merge))
teaforthecat / in-many.clj
Created Feb 14, 2018
Hugsql custom parameter type to protect against Oracles maximum in clause items of 1000
View in-many.clj
(defmethod hugsql.parameters/apply-hugsql-param :in-many
[param data options]
(let [in-clause-split-by (get options :in-clause-split-by 1000) ;; 1000 is Oracle's max
singl-map (get options :singularize-map);; override singularize
values (get-in data (hugsql.parameters/deep-get-vec (:name param)))
singularize (fn [s] (string/replace s #"s$" ""))
column (get singl-map (:name param) (singularize (name (:name param))))
prefix (str column " in ")
join-or (str " or " column " in " )
teaforthecat / real_date.clj
Created Feb 13, 2018
Protect against hard to catch date corruption
View real_date.clj
(defn date?
"Ensure a date string is a date and after a cutoff date. This protects against technically valid but corrupt dates like from a century ago or in the future."
;; store the year 10 years from now so we don't have to compute it every call
(date? s 2010 `~(+ 10 (clj-time.core/year (clj-time.core/now)))))
([s past-cutoff future-cutoff]
(if-let [d
teaforthecat / collate_transducer.clj
Last active Feb 5, 2018
a descriptive experiment making a clojure transducer
View collate_transducer.clj
(defn collate
"This is a transducer for collecting things that are connected in series. It
will store one previous input. The previous input can then be compared to it's
successor using COMPARES-FN and optionally integrated into a single output
COMPARES-FN must accept 2 arguments, being 2 inputs (which are in order)
COLLATE-FN must accept 2 arguments, being an accumulator and an input
COLLATE-FN is a reducing function. A third arg can be given as the starting
teaforthecat / bones-editable-concept.clj
Created Jan 5, 2017
example showing intent of bones-editable library
View bones-editable-concept.clj
(defn detect-controls [{:keys [enter escape]}]
(fn [keypress]
(case (.-which keypress)
13 (enter)
;; chrome won't fire 27, so use on-blur instead
27 (escape)
(defn field [form-type identifier attr html-attrs]
(let [path [:editable form-type identifier :inputs attr]
You can’t perform that action at this time.