Last active
February 11, 2019 10:07
-
-
Save li1/aa75a18fa6eab6c05fbbc983b8026701 to your computer and use it in GitHub Desktop.
Formats 3DF diffs as they arrive in the repl into a more concise form
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 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