Skip to content

Instantly share code, notes, and snippets.

View philadelphia.clj
(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
View qsub.clj
(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))
View scratch.clj
(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
View reconnecting_websocket.clj
(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)
View bucket.clj
(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
View xfs.clj
(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)))
View split-thing.clj
(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)
View strat.cljc
(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 Jan 30, 2020
A draft of a time series query language
View ts_query.clj
;;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 Feb 10, 2021 — forked from jdf-id-au/transit-connection.cljc
Sketch for connecting henryw374/time-literals to transit
View deps.edn
{: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"}
}}