Skip to content

Instantly share code, notes, and snippets.

View lnostdal's full-sized avatar
🎧
Clojure, PostgreSQL, Linux

Lars Rune Nøstdal lnostdal

🎧
Clojure, PostgreSQL, Linux
View GitHub Profile
@lnostdal
lnostdal / trend-1 XBTUSD 2h [bt-9 branch].txt
Last active March 11, 2019 21:29
trend-1 XBTUSD 2h [bt-9 branch]
687a0ac
@lnostdal
lnostdal / trend-1 XBTUSD 15sec [bt-8 branch].txt
Created February 27, 2019 10:41
trend-1 XBTUSD 15sec [bt-8 branch]
8d69b3b
@lnostdal
lnostdal / trend-1 XBTUSD 1min [bt-7 branch].txt
Last active February 27, 2019 06:17
trend-1 XBTUSD 1min [bt-7 branch]
b87b5ff -->
@lnostdal
lnostdal / trend-1 XBTUSD 5min [bt-6 branch].txt
Last active February 26, 2019 13:04
trend-1 XBTUSD 5min [bt-6 branch]
37167d096394547c3fbbdb28e99ca3e4dec8fb2c -->
@lnostdal
lnostdal / clj_bug.clj
Last active February 6, 2019 03:55
clojure compiler bug?
;; maybe something related to locals clearing and/or forwarding of bindings (?)
;; warning: this will lead to heap overflow quite fast!
(let [s (range)]
(if true
(future
(loop [s s]
(recur (rest s))))
:whatever))
@lnostdal
lnostdal / lazy-seq + seque.clj
Last active January 19, 2019 05:27
Clojure for fast processing of streams of data via LAZY-SEQ and SEQUE
;; www.Quanto.ga
;;
;; * You have a stream of data where generating each new element for the stream takes some time.
;; * You consume and do some calculations on each element from the stream; this too takes some time.
;; * When the consumer is done with its calculations for a element (or chunk of elements!) you do
;; not want it to wait around for the code that fetches new elements to finish fetching a new element
;; -- because this could be done in the background while you where doing the calculations.
;;
;; A way to deal with this is to use SEQUE which will keep production N steps in advance of consumption
;; via a background thread that works on Clojue seqs.
@lnostdal
lnostdal / async-consume-buffer.clj
Last active January 10, 2019 02:29
clojure.core.async: consume channel buffer without blocking
;; www.Quanto.ga
;;
;; I've found this to be useful at times:
(defn async-consume-buffer
"Consume as many values from `ch` as possible without blocking.
Once `ch` blocks (i.e. its buffer is empty), the values are returned as a vector."
([ch]
(async-consume-buffer ch false))
@lnostdal
lnostdal / interactive_brokers_test.clj
Last active July 31, 2018 22:26
Interactive Brokers API test in Clojure
(def %bnds (get-thread-bindings)) ;; TODO: Seems kind of hacky, but needed as sometimes (EWrapper/error Exception) is sourced from different threads(!).
(deftype IB
[^:unsynchronized-mutable ^int next-order-id
^:unsynchronized-mutable ^com.ib.client.EClient eclient
^:unsynchronized-mutable ^com.ib.client.EReaderSignal ereader-signal]
com.ib.client.EWrapper
@lnostdal
lnostdal / ma_array_vs_ma_transducer.clj
Last active August 20, 2018 02:24
Moving average in Clojure using JVM arrays vs. transducer variant
;; ...and yes; I know there are more efficient ways to do this.
(defn sma ^doubles [^doubles pseries ^long ma-len]
"Simple Moving Average: https://en.wikipedia.org/wiki/Moving_average#Simple_moving_average
Returns a JVM double[]. Head is padded with ##NaN entries to align it with `pseries`."
(if (= ma-len 1)
pseries
(let [pseries-len (alength pseries), ret (double-array pseries-len ##NaN)]