Skip to content

Instantly share code, notes, and snippets.

(defn non-caching-riemann-client
[{:keys [host port] :as riemann-config}]
(assert host)
(assert port)
(let [c (riemann.client/tcp-client :host host :port port)]
;; disable dns caching
;; If we let riemann cache dns lookups, it can't reconnect to the riemann server after that restarts
(-> c
.transport
.transport
;; fontlock logic vars (for datomic and cascalog)
(font-lock-add-keywords
'clojure-mode
`((,(concat "\\<"
"\\?[a-z0-9-]+"
"\\>")
0
font-lock-keyword-face)))
(defmacro eval-with-bindings [bindings form]
(assert (even? (count bindings)) "an even number of forms in binding vector")
(let [binding-pairs (partition 2 bindings)
args (mapv first binding-pairs)
vals (map second binding-pairs)]
`((eval (fn ~args ~form))
~@vals)))
(let [foo inc]
(eval '(foo 1)))
;; Toggle a counter that tracks how manny times a function is called
(defn instrument-fn [f]
(let [counter (atom 0)]
(-> (fn [& args] ;; NOTE could unroll for 1-n args for speed
(swap! counter inc)
(apply f args))
(with-meta
{:uninstrumented f
:counter counter}))))
@ChrisBlom
ChrisBlom / gist:a061a966eaf431f34dd6537c500920dd
Created October 10, 2016 14:44 — forked from sebsto/gist:19b99f1fa1f32cae5d00
Install Maven with Yum on Amazon Linux
sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven
mvn --version
(defn invert
"inverts a graph represented as a map from source to target nodes"
[graph]
(reduce-kv (fn [acc src trgs]
(if (seq trgs)
(reduce (fn [acc- trg]
(update acc- trg (fnil conj #{}) src))
acc
trgs)
;; to preserve nodes without edges
(defun add-clj-format-before-save ()
(interactive)
(add-hook 'before-save-hook
'cider-format-buffer
t
t))
(add-hook 'clojure-mode-hook 'add-clj-format-before-save)
(let [l [0 0 1 1 1 14 5 13 6 3 ]
m [0.01 0.02 0.05 0.1 0.2 0.5 1 2 5 10 20 50 100]
subtotals (map * m l)
total (reduce + subtotals)]
(doseq [[munt totaal] (sort-by key > (zipmap m subtotals))]
(printf "%s\t%.2f%n" munt (float totaal)))
total)
@ChrisBlom
ChrisBlom / TimeGauge.kt
Created May 24, 2022 11:58
wrapper to create a easy to use timegauge
import io.micrometer.core.instrument.MeterRegistry
import io.micrometer.core.instrument.Tag
import java.time.Instant
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicLong
import java.util.function.ToDoubleFunction
fun MeterRegistry.timeGaugeMillis(name: String, tags: Iterable<Tag>, initialValue: Long = 0): (Instant) -> Unit {
val a = AtomicLong(initialValue)
a.apply {