This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns strat2 | |
(:require [dev.jt.clojiex :as iex] | |
[tick.alpha.api :as t] | |
[clojure.repl :refer :all] | |
[clojure.pprint :refer :all])) | |
;;gist version | |
(set! *print-length* 20) | |
(set! *print-level* 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def st {:things [{:x 1} {:x 2} {:x 3}] | |
:location 0}) | |
(defn advance [st] | |
(assert (< (:location st) (dec (count (:things st))))) | |
(let [old-loc (:location st) | |
new-loc (inc old-loc)] | |
(assoc st | |
:location new-loc | |
:last-changes {:last-item (nth (:things st) old-loc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn map-prev | |
"maps f over values. f is a function of two arguments, the previous and current value, which is mapped over each value. previous value is initially nil" | |
([f] | |
(let [vold (volatile! nil)] | |
(map (fn [x] | |
(let [old @vold] | |
(vreset! vold (f old x))))))) | |
([f xs] | |
(map f (cons nil xs) xs))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn bucket | |
[accf init-acc splitf] | |
(fn [rf] | |
(let [acc-atom (atom init-acc)] | |
(fn | |
([] (rf)) | |
([result] | |
(rf result)) | |
([result input] | |
(let [old-acc @acc-atom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn re-ws-stream [url] | |
(let [s (ms/stream 10) | |
renew-connection | |
(fn this | |
([] (this 0 (System/currentTimeMillis))) | |
([conn-ct prev-conn-ts] | |
(-> (http/websocket-client url {:max-frame-payload 1e7 :max-frame-size 1e7}) | |
(md/chain | |
(fn [conn] | |
(log/info "ws connected. connection count" conn-ct) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.core.async.impl.protocols :as impl] | |
'[clojure.core.async.impl.dispatch :as dispatch]) | |
;;=> nil | |
(extend-type java.util.concurrent.CompletionStage | |
impl/ReadPort | |
(take! [this handler] | |
(.whenCompleteAsync this | |
(reify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn -add-clause [accessor->clauses cl] | |
(let [[ax & clause] cl] | |
(update accessor->clauses ax (fnil conj #{}) clause))) | |
(defn get-matches [accessor->clauses input] | |
(set | |
(for [[ax clauses] accessor->clauses | |
[op & args :as clause] clauses | |
:let [match-val (cond-> [ax op] args (into args)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.core.async :as a | |
:refer [<! >! alt! alts! chan go go-loop poll! <!! >!!]]) | |
(import | |
com.paritytrading.philadelphia.FIXConfig | |
com.paritytrading.philadelphia.FIXConnection | |
com.paritytrading.philadelphia.FIXConfig$Builder | |
com.paritytrading.philadelphia.FIXConnection | |
com.paritytrading.philadelphia.FIXConnectionStatusListener | |
com.paritytrading.philadelphia.FIXMessage | |
com.paritytrading.philadelphia.FIXMessageListener |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:paths ["."] | |
:deps {time-literals/time-literals {:mvn/version "0.1.5"} | |
com.cognitect/transit-clj {:mvn/version "0.8.319"} | |
com.cognitect/transit-cljs {:mvn/version "0.8.256"} | |
}} |
OlderNewer