The Joy of Clojure - Resurrecting Firefox Tabs
This post isn't about the (awesome) book, it's about the immense ease and pleasure of interactive with data using Clojure.
Have you ever lost some tabs due to some browser hijinks (and a bit of goofing up)? I have recently. Rather than accept it, I decided to do some research and figure out that Firefox keeps all of this data in the deep dark corners of some json files. Knowing that, I fired up a repl with lein try clojure.org/data.json
and began work.
;; lein try clojure.org/data.json (require '[clojure.data.json :as json]) (def home (System/getenv "HOME") "/.mozilla/firefox/something.default") (def sessions ["sessionstore.bak" "sessionstore.bak-20140611075517" "sessionstore.js"]) (def data (->> (nth sessions 0) (str home "/") slurp json/read-json)) (->> data :_closedWindows first :tabs (map #(->> % :entries (map :url))) (map last) clojure.pprint/pprint)
After a bit of playing around I had this and tabs were restored.