Skip to content

Instantly share code, notes, and snippets.

Last active Feb 11, 2019
What would you like to do?
Formats 3DF diffs as they arrive in the repl into a more concise form
(ns diff-formatter)
(defn- extract-contents [[_ var-map time diff]]
(let [vars (map (comp read-string second) (re-seq #"\{\".*?\":(.*?)\}" var-map))]
[vars (read-string time) (read-string diff)]))
(defn format-diffs [data]
(let [[_ name content] (re-find #"\[\"(.*?)\",(.*)\]" data)
content-details (re-seq #"\[\[(?:(.*?)\],(\d+),(-?\d))*?\]" content)]
[name (map extract-contents content-details)]))
;; to quickly escape quotes, use e.g.
(def data "[\"chic/crew-earnings\",[[{\"String\":\"alfredo\"},{\"Number\":720}],2,1],[[{\"String\":\"bernado\"},{\"Number\":1220}],2,1],[[{\"String\":\"carlo\"},{\"Number\":1500}],2,1],[[{\"String\":\"cristiano\"},{\"Number\":1500}],2,-1]]")
(format-diffs data)
;; usage example from your clojure code
(def conn (df/create-publication "ws://" (comp clojure.pprint/pprint format-diffs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment