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
(import '(java.util Base64 UUID)) | |
(defn uuid-to-b64-url [^UUID uuid] | |
(.substring (.encodeToString (Base64/getUrlEncoder) | |
(-> (java.nio.ByteBuffer/wrap (byte-array 16)) | |
(.putLong (.getMostSignificantBits uuid)) | |
(.putLong (.getLeastSignificantBits uuid)) | |
.array)) | |
0 22)) |
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 on-the-client | |
(:require [cognitect.transit :as transit])) | |
;; Let's imagine the server has written the transit payload into this tag: | |
;; <script type="application/json" id="my-app-data">...</script> | |
;; This will output the original clojure data | |
(->> (js/document.getElementById "my-app-data") | |
.-innerHTML | |
(transit/read (transit/reader :json))) |
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 remux.core) | |
(defn create-store [handlers initial-state] | |
(let [state (atom initial-state) | |
dispatching? (atom false)] | |
{::state state | |
::get-state (fn get-state [] @state) | |
::get-raw-state #(state) | |
::dispatch | |
(fn [action-name data] |
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
(defn single-return-transducer | |
"Dummy transducer that simply returns the value given to it, | |
ignoring any accumulated value" | |
([] :initial-value-to-be-ignored) | |
([final-value] final-value) | |
([initial-value v] v)) | |
(defn using-xform--hazard-edition [chunks] | |
(transduce (comp (halt-when error?) | |
cat |
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
(defn using-xform--improved [chunks] | |
(transduce (comp (halt-when error?) | |
cat | |
(x/by-key :a x/count)) | |
conj | |
{} | |
chunks)) | |
(using-xform--improved chunks) | |
=> {0 3330, 1 3330, 2 3330} ;; Still works |
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
([to xform from] | |
(if (instance? clojure.lang.IEditableCollection to) | |
(with-meta | |
(persistent! (transduce xform conj! (transient to) from)) | |
(meta to)) | |
(transduce xform conj to from))) |
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
(original chunks) | |
=> {0 3330, 1 3330, 2 3330} ;; as expected! | |
;; Note that the standard deviation is huge here | |
(criterium/quick-bench (original chunks)) | |
" | |
Evaluation count : 294 in 6 samples of 49 calls. | |
Execution time mean : 10.778696 ms | |
Execution time std-deviation : 8.818884 ms | |
Execution time lower quantile : 1.680341 ms ( 2.5%) |
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
(def mini-chunks-with-error | |
[[{:a 0} {:a 1} {:a 2}] | |
[{:a 0} {:a 1} {:a 2}] | |
{:error "Something terrible has happened!"}]) | |
(original mini-chunks-with-error) | |
=> {:error "Something terrible has happened!"} | |
(using-xform mini-chunks-with-error) | |
=> Unhandled java.lang.ClassCastException |
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 '[net.cgrand.xforms :as x]) | |
(defn using-xforms [chunks] | |
(into {} | |
(comp (halt-when error?) | |
cat | |
(x/by-key :a x/count)) | |
chunks)) | |
(using-xforms chunks) |
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
(defn make-chunks [chunk-count chunk-size] | |
(for [i (range chunk-count)] | |
(for [j (range chunk-size)] | |
{:a (mod j 3)}))) | |
(def chunks (make-chunks 10 999)) |
NewerOlder