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
; Adapted from the clojure source code to work with babashka | |
; https://github.com/clojure/clojure/blob/c07c39cac49a91f6031fe05c2eb7a257aa089176/src/clj/clojure/core/server.clj | |
; original license info: | |
; Copyright (c) Rich Hickey. All rights reserved. | |
; The use and distribution terms for this software are covered by the | |
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
; which can be found in the file epl-v10.html at the root of this distribution. | |
; By using this software in any fashion, you are agreeing to be bound by | |
; the terms of this license. |
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
(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.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 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
(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 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
(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
(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
;;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 |
NewerOlder