Skip to content

Instantly share code, notes, and snippets.


Simon Gray simongray

View GitHub Profile
simongray / dataurl.clj
Created Jun 17, 2019
Helper functions for converting a DataURL to an image and saving to a file
View dataurl.clj
(defn dataurl->mime-type
"Extract the mime-type from a data URL."
(->> (str/split dataurl #",")
(re-find #":(.*?);")
(defn dataurl->image
"Extract the image data from a data URL."
simongray / dataurl.cljs
Created Jun 17, 2019
Conversion functions between DataURL and Blob type
View dataurl.cljs
;; Based on the implementations found here:
(defn dataurl->blob
(let [arr (str/split dataurl #",")
mime (second (re-find #":(.*?);" (first arr)))
bstr (js/atob (second arr))
n (count bstr)
u8arr (-> (map (fn [i] (.charCodeAt bstr i)) (range n))
View gist:6fd9717026b644db7030b2986ddbf5a5
(defn enumerated
(apply str (concat (interleave (drop-last 2 xs) (repeat ", "))
(interpose " og " (take-last 2 xs)))))
(println (enumerated ["a"]))
(println (enumerated ["a" "b"]))
(println (enumerated ["a" "b" "c"]))
(println (enumerated ["a" "b" "c" "d"])))