Last active
May 26, 2021 11:39
-
-
Save phrohdoh/2091a66bdb738076c2c0d54cdac12873 to your computer and use it in GitHub Desktop.
assorted clojure snippets
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.spec.alpha :as spec] | |
#_'[clojure.string :as str] | |
#_'[clojure.edn :as edn] | |
#_'[clojure.java.io :as io] | |
;; non-stdlib deps | |
'[clojure.spec.gen.alpha :as spec-gen] ;; org.clojure/test.check 1.1.0 | |
'[clojure.data.json :as json] ;; org.clojure/data.json 2.3.1 | |
#_'[datascript.core :as ds] ;; datascript 1.1.0 | |
#_'[datascript.transit :as dsts]) ;; datascript-transit 0.3.0 | |
;; ----------------------------------------------------------------------------- | |
;; ----------------------------------------------------------------------------- | |
#_#_ | |
;; [datascript "1.1.0"] | |
;; [datascript-transit "0.3.0"] | |
(require '[datascript.transit :as t]) | |
(let [db-str (slurp "/full/path/to/your/index.transit") | |
db (datascript.transit/read-transit-str db-str)] | |
(datascript.core/datoms db :eavt)) | |
;; ----------------------------------------------------------------------------- | |
;; ----------------------------------------------------------------------------- | |
#_#_ | |
(defn load-edn [source] | |
(try | |
(with-open [r (clojure.java.io/reader source)] | |
(clojure.edn/read (java.io.PushbackReader. r))) | |
(catch java.io.IOException e | |
(printf "couldn't open '%s': %s\n" source (.getMessage e))) | |
(catch RuntimeException e | |
(printf "error parsing edn file '%s': %s\n" source (.getMessage e))))) | |
(load-edn "/workspaces/ubdgt-clj/resources/ynab-export.edn") | |
;; => {"data" {"budget" {"transactions" [{"id" "some-txn-id"}]}}} | |
;; ----------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment