Skip to content

Instantly share code, notes, and snippets.

Chris Thompson teaforthecat

  • Saint Paul, MN
Block or report user

Report or block teaforthecat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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]

Keybase proof

I hereby claim:

  • I am teaforthecat on github.
  • I am teaforthecat ( on keybase.
  • I have a public key ASB1dfXKtsulaHTXHgRPQC4pzMzpu2CbqIJGJOEw2whMcwo

To claim this, I am signing this object:

teaforthecat / personal_consumer.clj
Last active Dec 26, 2015
Consume a kafka message stream of filtered keys
View personal_consumer.clj
(def consumer-registry (atom {}))
(defn get-or-create-message-stream [topic]
(if-let [message-stream (get @consumer-registry topic)]
(let [[cnsmr messages] (kafka/open-consumer "consumer-registry" topic)
new-message-stream (ms/->source messages)]
;; create lifespan for consumer of 1 minute, should probably be a component
(a/go (a/<! (a/timeout 60e3 ))
(kafka/shutdown cnsmr)
You can’t perform that action at this time.