Skip to content

Instantly share code, notes, and snippets.

View pingles's full-sized avatar

Paul Ingles pingles

View GitHub Profile
@pingles
pingles / riemann_nginx_req_rate.clj
Last active December 19, 2015 21:18
request rate
(let [index (default :ttl 300 (update-index (index)))]
(streams
(where (tagged "nginx")
#(info "nginx" %)
(with {:metric 1.0
:service "nginx.reqs.second"}
(by [:host]
(rate 5 index #(info "rate" %)))))
ContentTypes = ["text/html" => "html",
"text/html; charset=utf-8" => "html",
"image/png" => "image",
"image/jpeg" => "image",
"image/gif" => "image",
"text/css" => "css",
"application/x-javascript; charset=utf-8" => "js",
"-" => "unknown",
"application/json; charset=utf-8" => "js",
"application/font-woff" => "font",
(map (comp #(read-str % :key-fn keyword) #(String. %) :data #(data c (str "/brokers/ids/" %))) (children c "/brokers/ids"))
@pingles
pingles / sessionise.clj
Created May 28, 2013 18:18
Sessionising a sequence of numbers, fun with @Quantisan at the end of today
(defn abs [x]
(if (neg? x)
(- x)
x))
(defn session-id
([x] x)
([x y] (if (> (abs (- x y))
*threshold*)
(max x y)
$ brew install unixodbc
$ brew tap pingles/homebrew-psqlodbc
$ brew install psqlodbc
# can now check the connection...
$ isql -v redshiftodbc
+---------------------------------------+
| Connected! |
require(redshift)
conn <- redshift.connect("jdbc:postgresql://mycluster.redshift.amazonaws.com:5439/data", "user", "pass")
# we can retrieve a list of tables
tables <- redshift.tables(conn)
# and get some info about the columns in one of those tables
cols <- redshift.columns(conn, "weblog")
@pingles
pingles / if_let_multi.clj
Last active July 26, 2016 23:58
Clojure if-let accepting multiple bindings
(ns if-let-multi-bind.core)
(defmacro if-let*
([bindings then]
`(if-let* ~bindings ~then nil))
([bindings then else & oldform]
(let [test (cons #'and (map last (partition 2 bindings)))]
`(if ~test
(let ~bindings
~then)
(require '[langohr.consumers :as lcm])
(lcm/subscribe ch "images.resize"
(fn [ch metadata ^bytes payload]
(println (format "[consumer] %s received %s"
username
(String. payload "UTF-8"))))
:auto-ack true)
(defn subscriber-seq
[ch qname]
(let [[message-seq put] (pipe)]
(letfn [(message-handler [ch msg-meta payload])
(put {:ch ch :msg-meta msg-meta :payload payload})]
(lc/subscribe ch qname message-handler :auto-ack true))
message-seq))
(defn payload-str
[x]
(defn json-payload
[_ _ payload]
(read-json (String. payload "UTF-8")))
(defn subscriber-seq
[ch qname handler]
(let [[message-seq put] (pipe)]
(lc/subscribe ch qname (comp put handler) :auto-ack true)
message-seq))