This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; basic version | |
(set! *unchecked-math* false) | |
(defn gaussian-logpdf | |
"Returns log probability of `x` under a gaussian distribution parameterized | |
by shape parameter `mu`, with optional scale parameter `sigma`." | |
[x {:keys [mu sigma]}] | |
(let [z-inv (* -0.5 (+ (math/log sigma) | |
(math/log 2.0) | |
(math/log math/PI))) | |
px (* -0.5 (math/pow (/ (- x mu) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; primitive-math is a low-level Clojure math library that | |
;; warns you if reflection is being used in your math pathway. | |
;; This demonstrates how it improves over the default Clojure | |
;; math fns, by preventing accidental reflection. | |
;; It's possible to get part of this behavior from core Clojure | |
;; by setting *unchecked-math* to :warn-on-boxed, but this only | |
;; applies to a fraction of the fns that primitive-math covers. | |
;; In particular, just +, -, *, inc, dec, and the casts. | |
;; primitive-math will also cover divison, bool operations, bit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(in-ns 'user) | |
(require '[manifold.stream :as s]) | |
(defn flaky | |
[x] | |
(if (< (rand-int 10) 2) | |
(throw (Exception. "flaky")) | |
x)) | |
(defn reliable-add-sentinel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Move this to .git/hooks/pre-commit | |
# echo "Running pre-commit hook..." | |
# Check if project.clj file has been modified | |
if git diff --cached --name-only | grep -q "^project.clj$"; then | |
echo "project.clj modified, running lein-to-deps" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# A script to show you outdated brew formulae, but only if they're leaves. | |
# Who wants to scan through intermediate libs? | |
set -euo pipefail | |
# set -x # echo commands to terminal; for debugging | |
# with comm - slower for me, but may work better for you? | |
# FORMULAE=$(comm -12 <(brew outdated --quiet | sort) <(brew leaves)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro defmulti+ | |
"An enhanced version of defmulti that unmaps itself from the ns when present. | |
Eases the pain of redefining the dispatch method at the REPL." | |
[name & args] | |
`(do | |
(when (resolve '~name) | |
(ns-unmap *ns* '~name)) | |
(defmulti ~name ~@args))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[manifold.stream :as s]) | |
(defn coerce-seq | |
"if the page should happen to be an Exception, wrap | |
it in a vector so that it can be concatenated to the | |
value stream" | |
[v] | |
(if (sequential? v) v [v])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(utils/when-class java.util.concurrent.SubmissionPublisher | |
(import '(java.util.concurrent SubmissionPublisher)) | |
(s/def-sink SubmissionPublisherSink | |
[^SubmissionPublisher publisher | |
^AtomicReference last-put] | |
(isSynchronous [_] | |
false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
# Use like: | |
# LCP=$(lein classpath) # in case you need to rerun it and don't want to wait on Leiningen | |
# search-classpath.sh $LCP tools.reader | |
# search-classpath.sh $LCP Reader.class | |
# ...etc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
King-Mob:~ $ HOMEBREW_MAKE_JOBS=1 VERBOSE=1 brew install leiningen2 | |
==> Downloading https://github.com/technomancy/leiningen/zipball/master | |
Already downloaded: /Library/Caches/Homebrew/leiningen2-2.0.0-preview6.zip | |
/usr/bin/unzip /Library/Caches/Homebrew/leiningen2-2.0.0-preview6.zip | |
Archive: /Library/Caches/Homebrew/leiningen2-2.0.0-preview6.zip | |
db69ddedff3945cfdaec7a9a53d25e6236a0e78f | |
creating: technomancy-leiningen-db69dde/ | |
inflating: technomancy-leiningen-db69dde/.gitattributes | |
inflating: technomancy-leiningen-db69dde/.gitignore | |
inflating: technomancy-leiningen-db69dde/.travis.yml |