Skip to content

Instantly share code, notes, and snippets.

View teaforthecat's full-sized avatar

Chris Thompson teaforthecat

View GitHub Profile

Keybase proof

I hereby claim:

  • I am teaforthecat on github.
  • I am teaforthecat (https://keybase.io/teaforthecat) on keybase.
  • I have a public key ASB1dfXKtsulaHTXHgRPQC4pzMzpu2CbqIJGJOEw2whMcwo

To claim this, I am signing this object:

@teaforthecat
teaforthecat / personal_consumer.clj
Last active December 26, 2015 14:19
Consume a kafka message stream of filtered keys
(def consumer-registry (atom {}))
(defn get-or-create-message-stream [topic]
(if-let [message-stream (get @consumer-registry topic)]
message-stream
(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)
@teaforthecat
teaforthecat / jobs.clj
Created December 18, 2015 03:30
An onyx job builder, basically a shortcut to this: kafka-input->function->kafka-output
(ns bones.jobs
" given a symbol and config, build all components of an onyx job
with three tasks kafka-input->function->kafka-output
(def x.y/fn [s] (str s \"-yo\"))
(api/submit-jobs (bones.jobs/build-jobs {} [:x.y/fn]))
(kafka/produce \"x.y..fn-input\" \"hello\")
(kafka/consume \"x.y..fn-output\") => \"hello-yo\"
")
(defn topic-reader [^String topic]
@teaforthecat
teaforthecat / clj-kafka-test.clj
Last active December 2, 2015 04:44
trying to fetch data from kafka, not being able to use "take"
(defn consumer-config [] {"zookeeper.connect" "localhost:2182"
"group.id" (str (java.util.UUID/randomUUID))
"auto.offset.reset" "smallest"
"auto.commit.enable" "false"})
(defn fetch-first [topic]
(with-resource [c (zk/consumer (consumer-config))]
zk/shutdown
(first (zk/messages c topic))))
@teaforthecat
teaforthecat / comment-or-uncomment-sexp.el
Created October 18, 2015 18:10
one function with a few lines addded to keep the structure of lisp forms when commenting a form inside another form
(defun comment-sexp--raw ()
"Comment the sexp at point or ahead of point."
(pcase (or (bounds-of-thing-at-point 'sexp)
(save-excursion
(skip-chars-forward "\r\n[:blank:]")
(bounds-of-thing-at-point 'sexp)))
(`(,l . ,r)
(goto-char r)
(skip-chars-forward "\r\n[:blank:]")
(save-excursion
@teaforthecat
teaforthecat / gist:85c518b3164445602334
Last active August 29, 2015 14:23
neat idea to bookmark commands
;; not working: service is not found in services;
(let ((service (prodigy-define-service
:name "* head *"
:cwd "~/.emacs.d/lisp"
:command "head"
:args '("my-functions.el")
))
)
(prodigy-start-service service))
@teaforthecat
teaforthecat / gist:d5921a1516f27877ddda
Created July 13, 2014 01:50
broken upsert transaction
;; implicit upsert due to unique constraint on message
;; temp id will get replaced with real id if message exists
(defn upsert-message-tx [greeting]
(let [tempid (d/tempid :db.part/user -1 )]
[{ :db/id tempid
:greeting/message greeting}
[:inc tempid :greeting/hit-count 1]]))
@teaforthecat
teaforthecat / project.clj
Created May 7, 2014 02:53
offending lein project file with dependencies configured to trigger a bug in clojurescript compilation. "NoSuchMethodError: com.google.common.io.ByteStreams.limit"
(defproject intrepid-life-coffee "0.1.0-SNAPSHOT"
:description "website to advertise the coffee shop"
:url "www.intrepidlifecoffee.com"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.6"]
[ring "1.2.1"]
[hiccup "1.0.5"]
;; [org.slf4j/log4j-over-slf4j "1.6.6"] ;;avoids dep loop
@teaforthecat
teaforthecat / common.yaml
Created December 1, 2013 00:00
puppet-hiera hash data access fails why?
nfs_volumes:
home: "%{gdnet_env}-netapp1:/vol/home/qtree0"
yum_cache: "%{gdnet_env}-netapp1:/vol/yum_cache/qtree0"
techops: "%{gdnet_env}-netapp1:/vol/techops/qtree0"
websites: "%{gdnet_env}-netapp1:/vol/websites_%{gdnet_env}/qtree0"
apache_logs: "%{gdnet_env}-netapp1:/vol/apache_logs_%{gdnet_env}/qtree0"
evolution_logs: "%{gdnet_env}-netapp1:/vol/evolution_logs_%{gdnet_env}/qtree0"
@teaforthecat
teaforthecat / ruby.el
Created March 21, 2013 01:33 — forked from fujin/ruby.el
(setq ruby-deep-indent-paren nil)
(defadvice ruby-indent-line (after unindent-closing-paren activate)
(let ((column (current-column))
indent offset)
(save-excursion
(back-to-indentation)
(let ((state (syntax-ppss)))
(setq offset (- column (current-column)))
(when (and (eq (char-after) ?\))
(not (zerop (car state))))