View hystrix-clj-snippets.clj
(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 '[com.netflix.hystrix.core :as hystrix])
View cursive.txt
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(FileContentImpl.java:189)
at cursive.index.PsiDependentIndexExtension$1$1.valAt(PsiDependentIndexExtension.java:61)
at cursive.index.PsiDependentIndexExtension$1$1.valAt(PsiDependentIndexExtension.java:51)
at clojure.lang.KeywordLookupSite$1.get(KeywordLookupSite.java:45)
at plugin.index.js$index_javascript.invoke(js.clj:196)
View merge.clj
(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)
View mr-jr.clj
(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
(async/reduce
View async-transient.clj
; 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!)
(async/<!!))
;=>
; Exception in thread "async-dispatch-52" java.lang.IllegalAccessError: Transient used by non-owner thread
View radio-binding.clj
(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")])))
pack!
View shaped-window-demo.clj
; http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/uiswing/examples/misc/ShapedWindowDemoProject/src/misc/ShapedWindowDemo.java
(use 'seesaw.core)
(require '[seesaw.graphics :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)))))])
View scala-rx
[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(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
View explain.md

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.

View after-undo.clj
(defn foo
[context] (wrap-router
(wrap-router (comp output-queue-map
(routing-table %)
:type)))