Skip to content

Instantly share code, notes, and snippets.

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:

(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))
@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)
@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)]
;; 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 / bots.clj
Last active December 19, 2015 00:19 — forked from cgrand/bots.clj
;; tc
(ns tron.bots
(:require [tron.core :as tron]))
;;bot func: tc
(defn empty-look
"A mock look function which just checks for the arena
boundaries."
@tcoupland
tcoupland / QuickSort_codeGolf.clj
Created June 13, 2012 16:39
Quicksort in Code Golf
(defn f [s p v] (filter #(s % p) v))
(defn s [w]
(if-let [p (first w)]
(if-let [v (rest w)]
(concat (s (f < p v)) [p] (s (f >= p v)))
p)
()
))
@tcoupland
tcoupland / dijkstra-core.clj
Created May 29, 2012 22:13
Brisfunctional dojo code implementing dijkstra's algorithm 29-05-2012
(ns dijkstra.core)
(def edges {:A {:F 14 :C 9 :B 7}
:B {:A 7 :C 10 :D 15}
:C {:A 9 :B 10 :D 11 :F 2}
:D {:B 15 :C 11 :E 6}
:E {:D 6 :F 9}
:F {:A 14 :C 2 :E 9}})
(def inf Integer/MAX_VALUE)
@tcoupland
tcoupland / compojureHandler5.clj
Created April 28, 2012 11:40
Simple compojure handler try finally
(defn logging [chain] (fn [req]
(println "before")
(try (chain req) (finally (println "after")))
))
@tcoupland
tcoupland / compojureHandler4.clj
Created April 28, 2012 11:36
Simple compojure handler before msg only
(defn logging [chain] (fn [req]
(println "before")
(chain req)))