Skip to content

Instantly share code, notes, and snippets.

View daveray's full-sized avatar

Dave Ray daveray

View GitHub Profile
@daveray
daveray / exception.clj
Created March 9, 2013 04:45
Why does `lein repl` print `(.getCause e)` when an exception occurs rather than the actual exception? This had me scratching my head for a while today.
clawk.main=> (java.net.URI/create ":")
URISyntaxException Expected scheme name at index 0: : java.net.URI$Parser.fail (URI.java:2810)
clawk.main=> *e
#<IllegalArgumentException java.lang.IllegalArgumentException>
(defn ^Observable drop-while
[f ^Observable xs]
(Observable/create (fn [^Observable subject]
(let [dropping (atom true)
subscription (subscribe* xs
(fn [v]
(when (or (not @dropping)
(not (reset! dropping (boolean (f v)))))
(emit subject v)))
(fn [e] (error subject e))
@daveray
daveray / video_example.clj
Created February 6, 2013 18:44
Port of rx video example from Groovy to Clojure
(ns rx.examples.clojure.video-example
(:import [rx Observable Observer Subscription]))
(defn video-list
[position]
{:position position
:name (str "ListName-" position) })
(defn ^Observable video-list->videos
[{:keys [position] :as video-list}]
@daveray
daveray / hystrix.txt
Created January 3, 2013 13:43
Hystrix-clj
Functions for defining and executing Hystrix dependency commands and collapers.
The definition of commands and collapers is separated from their instantiation and execution.
They are represented as plain Clojure maps (see below) which are later instantiated into
functional HystrixCommand or HystrixCollapser instances.
A command definition map can be passed to the execute, and queue functions
to invoke the command.
HystrixCommand
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':hystrix-contrib:hystrix-clj:dependencies'.
> Could not resolve all dependencies for configuration ':hystrix-contrib:hystrix-clj:clojuresque'.
> Could not find group:clojuresque, module:runtime, version:1.5.4-SNAPSHOT.
Required by:
com.netflix.hystrix:hystrix-clj:1.1.7-SNAPSHOT
@daveray
daveray / seesaw-prize.clj
Created December 7, 2012 18:17
400th Seesaw watcher prize
; First, your Javadoc: http://docs.oracle.com/javase/6/docs/api/javax/swing/JFrame.html
; and next, your JLabels:
(ns seesaw-prize
(:require [seesaw.core :refer [label]]))
(def all-the-jlabels (map (comp label str) (range)))
; feel free to clojure.core/take as many as you need.
@daveray
daveray / fail-goal.clj
Created November 23, 2012 07:00
core.logic goal failure check
; clojure 1.4.0, core.logic 0.8.0-beta2
user=> (use 'clojure.core.logic)
nil
user=> (defn list?o
[v]
(conde
[(emptyo v)]
[(fresh [f] (firsto v f))]))
#'user/list?o
@daveray
daveray / flatteno.clj
Created November 23, 2012 06:16
flatteno
(defn list?o
[v]
(matche [v]
([[]] succeed)
([[_ . _]] succeed)))
(defn flatteno
[in out]
(matche [in]
([[]] (== out in))
@daveray
daveray / typed-clojure.txt
Created October 28, 2012 05:11
typed clojure typos
1.2 Motivation, second sentence: "This is idea not new"
page 18: "singleton types in ATTT a much more advanced"
page 21: "We now have sufficient information to synthesise the type of listing 2.2 to be (List Float)".
Should that be "... to be (LazySeq Float)"?
page 22: "Colored Local Type Inference is a candidate for"
Should there be more here, or is that leading into 2.9?