Skip to content

Instantly share code, notes, and snippets.

View tcoupland's full-sized avatar

Tom Coupland tcoupland

View GitHub Profile
;; Clojure 1.5.1
=> 1
1
=> (require '[clojure.core.reducers :as r])
nil
=> (use 'clojure.repl)
nil
=> (doc r/fold)
-------------------------
clojure.core.reducers/fold
@tcoupland
tcoupland / partition-or-time.clj
Last active August 29, 2015 14:10
A channel modifier that creates batches of events either when a given number of events have been put into it or when a given time period has expired.
(defn partition-or-time
"Returns a channel that will either contain vectors of n items taken from ch or
if beat-rate millis elapses then a vector with the available items. The
final vector in the return channel may be smaller than n if ch closed before
the vector could be completely filled."
[n ch beat-rate buf-or-n]
(let [out (chan buf-or-n)]
(go (loop [arr (make-array Object n)
idx 0
beat (timeout beat-rate)]
@tcoupland
tcoupland / data-binning.clj
Created October 14, 2015 15:30
Cascalog data binning code for making histograms
(defn one [& _] 1)
(defparallelagg counter
:init-var one
:combine-var +)
(defn mn
[data]
(<- [?mn]
(data :> ?v)
(defn -bool?
[x]
(cond
(boolean? x) x
(string? x) (case x
("true" "TRUE" "t" "T") true
("false" "FALSE" "f" "F") false
:clojure.spec/invalid)
:else :clojure.spec/invalid))

Keybase proof

I hereby claim:

  • I am mantree on github.
  • I am tcoupland (https://keybase.io/tcoupland) on keybase.
  • I have a public key ASDGaJd7dxtJb62pe1CwOnD7mQzfYyleZyZ9F3xE5mi9Rwo

To claim this, I am signing this object: