Skip to content

Instantly share code, notes, and snippets.

View daveray's full-sized avatar

Dave Ray daveray

View GitHub Profile
@daveray
daveray / hystrix-clj.clj
Last active December 24, 2015 13:09
hystrix clj bindings
; https://github.com/Netflix/Hystrix
; Hystrix is a latency and fault tolerance library designed to
; isolate points of access to remote systems, services and 3rd party
; libraries, stop cascading failure and enable resilience in complex
; distributed systems where failure is inevitable.
; Define a vanilla function
(defn search
"Fault INtolerant search"
@daveray
daveray / rx-let-o.clj
Created October 2, 2013 20:19
rx/let-o
(ns com.netflix.indigena.rx.graph
"This is an implementation namespace. Don't use it directly. Use the symbols
in com.netflix.indigena.rx"
(:require [clojure.set :as set]))
(def ^:private -ns- *ns*)
(set! *warn-on-reflection* true)
(defn ^:private ->let-o*-observable
[^rx.Observable o n name]
@daveray
daveray / rx-clj.md
Created August 29, 2013 20:19
Rx + Clojure Near-term Plans

Posted to Clojure Google Group, but it's not showing up there (https://groups.google.com/forum/#!topic/clojure/GITSKLmFM60), so...

In an effort to simplify the implementation and improve the RxJava experience for all JVM-based languages, we'll be dropping direct IFn support (and Groovy closure, Ruby proc, etc) in the next release. Instead, for each supported language (Scala, Groovy, and Clojure at the moment), we'll be providing a set of utility functions/macros/implicits to assist with interop. In the Clojure case, this will consist of a namespace, probably rx.lang.clojure, with the following helpers:

@daveray
daveray / chunk.clj
Created August 27, 2013 15:21
chunk a sequence of observables
(defn chunk
"Same as rx.Observable.merge(Observable<Observable<T>>) but the input Observables
are \"chunked\" so that at most chunk-size of them are \"in flight\" at any given
time.
The order of the input Observables is not preserved.
The main purpose here is to allow a large number of Hystrix observables to
be processed in a controlled way so that the Hystrix execution queues aren't
overwhelmed.
@daveray
daveray / rx-fn.clj
Created August 25, 2013 03:45
rxjava Func* and Action* generators
(defmacro ^:private reify-callable
"Reify a bunch of Func* interfaces
prefix fully qualified interface name. numbers will be appended
arities vector of desired arities
f the function to execute
"
[prefix arities f]
(let [f-name (gensym "rc")]
@daveray
daveray / rx-try.txt
Created August 17, 2013 08:14
try in rx
rx/try
[(observable catch-clause* finally-clause?)]
Macro
A macro that takes the place of onErrorResumeNext, doFinally, and friends. The resulting
expression is an observable that acts as a pass through except for the way it handles
errors.
catch-clause => (catch ClassName name expr*)
finally-clause => (finally expr*)
(defn lookup
[dep-graph key]
(let [{:keys [deps fn]} (dep-graph key)
context (map (partial lookup dep-graph) deps) ]
(apply fn context)))
;###############################################################################
; Define some functions with deps encoded as metadata
(defn bar*
[a b]
(defn lookup
[dep-graph key]
(let [var (get dep-graph key)
context (->> (for [d (-> var meta :deps)]
[d (lookup dep-graph d)])
(into {}))]
(partial var context)))
;###############################################################################
; Define some functions with deps encoded as metadata
@daveray
daveray / hystrix.clj
Created May 28, 2013 21:16
Hystrix command property caching
(def init-fn-timeout (atom 5000))
(def init-fn-called (atom 0))
(defcommand init-fn-test-command
{:hystrix/group-key "init-fn-test-command"
:hystrix/thread-pool-key "init-fn-test-command"
:hystrix/init-fn (fn [hystrix-map setter]
(swap! init-fn-called inc)
(let [prop-setter (. com.netflix.hystrix.HystrixCommandProperties Setter)]
(doto setter
@daveray
daveray / astyanax-clj.clj
Last active December 16, 2015 16:40
astyanax clojure binding docs
; will open source in the near future. feedback/questions welcome.
(ns com.netflix.astyanax
"Clojure bindings for Cassandra via Astyanax
# Serializers
Serializer, when used in schemas (see below) are typically specified with a keyword.
The following are available, corresponding to the Astyanax serializers of the same
name:
:ascii, :big-integer, :boolean, :bytes, :char, :date, :double, :float, :integer