Skip to content

Instantly share code, notes, and snippets.

@li1 li1/diff_formatter.clj
Last active Feb 11, 2019

Embed
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)]))
(comment
;; to quickly escape quotes, use e.g. http://ergoemacs.org/emacs/elisp_escape_quotes.html
(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://127.0.0.1:6262" (comp clojure.pprint/pprint format-diffs)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.