Skip to content

Instantly share code, notes, and snippets.

View daveray's full-sized avatar

Dave Ray daveray

View GitHub Profile
daveray / hystrix-clj-snippets.clj
Last active August 29, 2015 14:04
hystrix clj snippets
(def user-prefs
{:type :command
:group-key :Cassandra
:command-key :GetUserPreferences
:run-fn (fn [user-id] ... do request ...)
:fallback-fn (fn [user-id] { ... default prefs ...})
:cache-key-fn (fn [user-id] (str user-id)) })
(require '[ :as hystrix])
daveray / cursive.txt
Created July 24, 2014 23:48
Cursive Error
Since upgrading to Cursive 0.1.30 I get errors like this at startup. Intellij 13.1.4.
Error while indexing /.../.gradle/caches/modules-2/files-2.1/... path to file ....js
To reindex this file IDEA has to be restarted: Cannot obtain text for binary file type : UNKNOWN
com.intellij.util.indexing.FileContentImpl$IllegalDataException: Cannot obtain text for binary file type : UNKNOWN
at com.intellij.util.indexing.FileContentImpl.getContentAsText(
at cursive.index.PsiDependentIndexExtension$1$1.valAt(
at cursive.index.PsiDependentIndexExtension$1$1.valAt(
at clojure.lang.KeywordLookupSite$1.get(
at plugin.index.js$index_javascript.invoke(js.clj:196)
daveray / merge.clj
Created January 30, 2014 05:42
merge a channel of channels in core.async
(defn merge+
"Takes a *channel* of source channels and returns a channel which
contains all values taken from them. The returned channel will be
unbuffered by default, or a buf-or-n can be supplied. The channel
will close after all the source channels have closed."
([in-ch] (merge+ in-ch nil))
([in-ch buf-or-n]
(let [out-ch (async/chan buf-or-n)]
(async/go-loop [cs [in-ch]]
(if-not (empty? cs)
daveray / mr-jr.clj
Created January 28, 2014 04:48
Map-Reduce Jr. via core.async
(ns mr-jr
(:refer-clojure :exclude [shuffle])
(:require [clojure.string :as string]
[clojure.core.async :as async]))
(defn async-group-by
"Kinda like clojure.core/group-by, but takes a channel and returns a channel"
[f g ch]
(->> ch
daveray / async-transient.clj
Last active January 4, 2016 10:59
transient + core.async
; Is there a way to tell assoc! "No really, I know what I'm doing."
; Do I know what I'm doing?
(->> (async/to-chan [[:a 1] [:b 2] [:c 3]])
(async/reduce (fn [acc [k v]]
(assoc! acc k v))
(transient {}))
(async/map< persistent!)
; Exception in thread "async-dispatch-52" java.lang.IllegalAccessError: Transient used by non-owner thread
daveray / radio-binding.clj
Created January 22, 2014 07:08
Seesaw radio button binding example
(use 'seesaw.core)
(require '[seesaw.bind :as b])
(def f (let [bg (button-group)
f (-> (frame :title "test"
:content (border-panel :center (text :id :text :text "hi")
:south (horizontal-panel :items
[(radio :group bg :text "enabled")
(radio :group bg :text "disabled")])))
daveray / shaped-window-demo.clj
Created December 30, 2013 14:20
(use 'seesaw.core)
(require '[ :as g])
(-> (doto (frame :undecorated? true
:content (border-panel :center (button :text "I am a button"))
:listen [:component-resized
(fn [e]
(.setShape (to-root e)
(g/ellipse (0 0 (width e) (height e)))))])
daveray / scala-rx
Created November 5, 2013 07:46
Follow the Scala setup instruction for Coursera reactive course
[info] Compiling 3 Scala sources to /Users/dray/mine/coursera-rx/quickcheck/target/scala-2.10/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.2. Compiling...
sbt appears to be exiting abnormally.
The log file for this session is at /var/folders/12/bkvfkd5j0fxbd0k1q71tqqnc49fbdt/T/sbt4624986011374152709.log
java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(
at java.lang.ClassLoader.defineClass(
daveray /
Created October 28, 2013 18:44
Explain yourself

Say you have a function that filters a user's viewing history (sequence of maps, one for each "view" record) based on a bunch of criteria:

  • User's country
  • User's A/B test allocations
  • Whether they watched a standalone movie or episode of a series.
  • How much they watched
  • Have they watched it before
  • etc

These are all combined in a non-trivial way to decide whether a viewing record is included in the output.

daveray / after-undo.clj
Last active December 25, 2015 20:39
With paredit.vim, put cursor on `output-queue-map` and hit "dab". Very strange things happen and undo doesn't even undo them. please read files in order: before.clj, after.clj, after-undo.clj.
(defn foo
[context] (wrap-router
(wrap-router (comp output-queue-map
(routing-table %)