Skip to content

Instantly share code, notes, and snippets.

(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
(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))
(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
(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)
(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
@jjttjj
jjttjj / xfs.clj
Created September 11, 2020 12:22
(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)))
(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)
(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)
@jjttjj
jjttjj / ts_query.clj
Last active January 30, 2020 16:36
A draft of a time series query language
;;The goal of this is to specify a query format which clients can use to request
;;time series data from a server. The two primary operations are `:seek`s, which
;;are database lookups, and `:calc`s which tell the server to calculate
;;something using a previous seek as an argument. The result of either a seek or
;;a calc can be either a vector of data points or a map of columns (column name
;;-> vector).
;;Queries are either maps of names to subqueries, or just a vector of
;;subqueries. In either case, the response mirrors the shape of the query, with
@jjttjj
jjttjj / deps.edn
Last active March 4, 2023 19:03 — forked from jdf-id-au/transit-connection.cljc
Sketch for connecting henryw374/time-literals to transit
{: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"}
}}