Instantly share code, notes, and snippets.

• Sort options
Last active Dec 23, 2019
profile all functions in a namespace
View deps.edn
 {:paths ["."] :deps {robert/hooke {:mvn/version "1.3.0"} com.taoensso/tufte {:mvn/version "2.0.1"}}}
Last active Nov 20, 2019
Clojure namespace declaration by functions experiment
View a.cljc
 (fn [params] { :namespace-name 'a :requires [] :defs '{ x (fn [y] (str "a's " y)) }})
Created Oct 18, 2019
reverse destructuring
View structure.cljc
 (defn put [f x] (let [is-str? (char? (first x)) sx (apply str x)] (cond (map? f) (into {} (map vec (partition 2 (if (even? (count x)) x (conj x nil))))) (vector? f) (if is-str? (conj f sx) (into f x)) (list? f) (if is-str? (cons sx f) (concat f x)) (set? f) (if is-str? #{sx} (into f x))))) (defn structure [s f] (mapv (fn [b a] (if (empty? b) (put b a) (let [r (structure a b)] (if (vector? b) (vec r) r)))) f (partition-all (int (/ (count s) (count f))) s))) (structure (range 32) [[[] #{}] [#{} [] []]]) => [[[0 1 2 3 4 5 6 7] #{15 13 12 11 9 14 10 8}]
Created Jul 22, 2019
Clojure eval right?
View right?.clj
 (let [eval-right? clojure.core/eval] (intern 'clojure.core 'eval (fn [form] (if (= 'right? (last form)) (eval-right? (butlast form)) 'right?))))
Created May 14, 2019
Make functions public
View defns--.clj
 (defn defns-- "Makes all private fns in the namespace with the given name public" [namespace-name] (doseq [[_ v] (filter (fn [[_ x]] (if (var? x) (-> x meta :ns ns-name #{namespace-name}) false)) (ns-map namespace-name))]
Last active Sep 24, 2018
A note on Clojurescript React interfaces
View gist:4671b105774bf31f1240a2f0c25febb2
Last active Aug 10, 2018
Unique upsert in Datomic
View upsert
 ; create attributes p and q, where p is unique identity (d/transact edb1 {:tx-data [{:db/ident :p :db/cardinality :db.cardinality/one :db/valueType :db.type/keyword :db/unique :db.unique/identity}]}) => (d/transact edb1 {:tx-data [{:db/ident :q :db/cardinality :db.cardinality/one :db/valueType :db.type/keyword}]}) => ; now add a datum (d/transact edb1 {:tx-data [{:p :a1 :q :x}]})
Created Jul 28, 2018
changing :db/unique
View change-unique.clj
 (defn make-attr-test [conn] (let [tx [ {:db/ident :y :db/cardinality :db.cardinality/many :db/valueType :db.type/ref :db/isComponent true} {:db/ident :ya :db/cardinality :db.cardinality/one :db/valueType :db.type/keyword} {:db/ident :yb :db/cardinality :db.cardinality/one :db/valueType :db.type/string} ]] (d/transact conn {:tx-data tx}))) (defn add-test-data [conn]
Created Feb 8, 2018
Comparison of checked-vs-unchecked-vs-if-vs-ifless
View collatz.clj
 (defn collatz [i] (if (even? i) (/ i 2) (+ 1 (* i 3))))(defn unchecked-collatz [i] (if (even? i) (unchecked-divide-int i 2) (unchecked-add-int 1 (unchecked-multiply-int i 3))))(defn ifless-collatz ([i] (ifless-collatz i (rem i 2))) ([i p] (+ (* p (+ 1 (* 3 i))) (* (- 1 p) (/ i 2)))))(defn unchecked-ifless-collatz ([i] (unchecked-ifless-collatz i (unchecked-remainder-int i 2))) ([i p] (unchecked-add-int (unchecked-multiply-int p (unchecked-add-int 1 (unchecked-multiply-int 3 i))) (unchecked-multiply-int (unchecked-subtract-int 1 p) (unchecked-divide-int i 2))))) (quick-bench (ifless-collatz 7))Evaluation count : 2353194 in 6 samples of 392199 calls. Execution time mean : 257.547841 ns Execution time std-deviation : 8.540479 ns Execution time lower quantile : 249.726040 ns ( 2.5%) Execution time upper quantile : 269.887290 ns (97.5%) Overhead used : 1.806094 ns=> nil(quick-bench (unchecked-ifless-collatz 7))Evaluation count :
Created Mar 4, 2018
Testing arity vs map function call speed in clojure
View arity-vs-map.clj
 (defn add [x y] (+ x y))=> #'user/add(defn addm [{x :x y :y}] (+ x y))=> #'user/addm(reduce (fn [r i] (addm {:x r :y i})) 0 (range 128))=> 8128(quick-bench (reduce (fn [r i] (add r i)) 0 (range 128)))Evaluation count : 270720 in 6 samples of 45120 calls. Execution time mean : 2.212768 µs Execution time std-deviation : 76.515990 ns Execution time lower quantile : 2.130557 µs ( 2.5%) Execution time upper quantile : 2.336060 µs (97.5%) Overhead used : 1.902301 nsFound 1 outliers in 6 samples (16.6667 %) low-severe 1 (16.6667 %) Variance from outliers : 13.8889 % Variance is moderately inflated by outliers=> nil(quick-bench (reduce (fn [r i] (add r i)) 0 (range 128)))Evaluation count : 265158 in 6 samples of 44193 calls. Execution time mean : 2.323233 µs Execution time std-deviation : 176.530052 ns Execution time lower quantile : 2.223932 µs ( 2.5%) Execution time upper quantile : 2.626066 µs (97.5%) Overhead used : 1.902301 nsFound 1 outl
You can’t perform that action at this time.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7818744,"math_prob":0.8271914,"size":267,"snap":"2019-51-2020-05","text_gpt3_token_len":72,"char_repetition_ratio":0.14828898,"word_repetition_ratio":0.0,"special_character_ratio":0.23220974,"punctuation_ratio":0.2,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9778882,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-22T06:12:39Z\",\"WARC-Record-ID\":\"<urn:uuid:a70c9096-d3cc-4fe9-8d59-47b600a3135c>\",\"Content-Length\":\"94938\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b7cc4c35-059b-4c10-a1ac-4074de9b2872>\",\"WARC-Concurrent-To\":\"<urn:uuid:520fe020-8633-47cf-8848-969707733d70>\",\"WARC-IP-Address\":\"192.30.253.118\",\"WARC-Target-URI\":\"https://gist.github.com/Hendekagon?direction=desc&sort=updated\",\"WARC-Payload-Digest\":\"sha1:OWOEQOU7J6A4OON6GQZWGPSGV3ICHVIZ\",\"WARC-Block-Digest\":\"sha1:FR4XASG2VPSPKUY676ZAJHMFYB75O247\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250606696.26_warc_CC-MAIN-20200122042145-20200122071145-00016.warc.gz\"}"}