I hereby claim:
- I am favila on github.
- I am favila (https://keybase.io/favila) on keybase.
- I have a public key whose fingerprint is 594B BA31 C16A BA70 3AF4 AFB5 173E 02EE 2F85 597C
To claim this, I am signing this object:
| (defn signed-literal [^String unsigned-hex-str] | |
| (let [s (-> (Long/parseUnsignedLong unsigned-hex-str 16) | |
| (Long/toString 16))] | |
| (if (.startsWith s "-") | |
| (str "-0x" (subs s 1)) | |
| (str "0x" s)))) |
| (ns stm-example.core | |
| "A somewhat realistic use of Clojure refs and dosync. | |
| In most cases you should use an atom: it will be simpler and faster. | |
| But you may need to use refs when: | |
| * You need to return something other than the entire state from a swap!. E.g., | |
| the id of a newly-created user, or whether an action succeeded. You can | |
| emulate this by adding a \"return value\" key to the atom on any state |
| (ns advent.a6 | |
| (:require [clojure.java.io :as io]) | |
| (:import (clojure.lang PersistentVector))) | |
| (set! *warn-on-reflection* true) | |
| (set! *unchecked-math* :warn-on-boxed) | |
| (defn input [] | |
| (slurp (io/resource "day6-part1-input"))) |
| (ns favila.read-edn.tag-readers | |
| "Common tag-reader maps for edn." | |
| (:require datomic.db | |
| datomic.function | |
| datomic.codec) | |
| (:import java.net.URI)) | |
| (defmethod print-method URI [^URI x ^Writer w] | |
| (doto w | |
| (.write "#uri ") |
| (def tx-fns | |
| [{:db/ident :db.fn/reset-attribute-values | |
| :db/doc "Transaction function which accepts an entity identifier, attribute identifier | |
| and set of values and expands to any additions and retractions necessary to | |
| make the final post-transaction value of the attribute match the provided | |
| values. Attribute values must be scalars. | |
| If multiple values are provided on a cardinality-one attribute you will get a | |
| datom conflict exception at transaction time." | |
| :db/fn (d/function |
| (defn sha1-hash-stream [^InputStream stream] | |
| (let [buffer (byte-array 8192) | |
| md (MessageDigest/getInstance "SHA-1")] | |
| (loop [] | |
| (let [taken (.read stream buffer 0 8192)] | |
| (if (> taken 0) | |
| (do (.update md buffer 0 taken) | |
| (recur)) | |
| (.digest md)))))) |
| (defn promise-all | |
| "Given a collection of takeable items, return a promise channel which will | |
| contain a vector of the next available value taken from every item, preserving | |
| order if it exists in the original collection. If any takeable is closed | |
| the promise will be closed. | |
| Runs as synchronously as possible using poll! and offer!, only becoming async | |
| if one of the takeable items is not immediately takeable. | |
| Example: |
| package mytransit; | |
| import com.cognitect.transit.TransitFactory; | |
| import com.cognitect.transit.WriteHandler; | |
| import com.cognitect.transit.Writer; | |
| import java.io.ByteArrayOutputStream; | |
| import java.io.OutputStream; | |
| import java.util.HashMap; |
I hereby claim:
To claim this, I am signing this object:
| ;; same thing using reduction over d/datoms. | |
| ;; Objective is to avoid realizing too much in memory | |
| ;; May still be slow, but won't OOM | |
| (defn orgs->max-fks [db] | |
| (reduce (fn [o->fk [content-eid _ content-fk]] | |
| (let [org-id (-> (d/entity db content-eid) | |
| :content/collection | |
| :collection/organization | |
| :db/id)] |