Skip to content

Instantly share code, notes, and snippets.

@joinr
joinr / usagedata.txt
Created April 16, 2021 14:57
usage data
dir defmulti defprotocol Type
..\spork 27 170 proto-dominant
..\tech.datatype 21 60 proto-dominant
..\clojure 28 35 proto-dominant
..\faster-multimethods 60 0 multi-dominant
..\dtype-next 2 32 proto-dominant
..\incanter 23 5 multi-dominant
..\clojure2d-examples 0 27 proto-dominant
..\fastmath 15 11 multi-dominant
..\penumbra 11 13 proto-dominant
@joinr
joinr / logos.clj
Last active April 13, 2021 08:02
compiling core.logic queries for a rules-based enumeration dsl
;;discussed at https://clojurians.zulipchat.com/#narrow/stream/151168-clojure/topic/rule.20based.20data.20manipulation/near/234283215
(ns logos.core
(:require [clojure.core.logic :refer :all :as l]))
(defn resolve-rule [ctx k]
(loop [res (ctx k)]
(if (and (keyword? res)
(contains? ctx res))
(recur (ctx res))
res)))
{:deps {overload-fn/overload-fn {:mvn/version "0.1.0"}
fastmeth/fastmeth {:mvn/version "0.1.0-SNAPSHOT"}
criterium/criterium {:mvn/version "0.4.6"}}
:aliaes {;; See https://github.com/cognitect-labs/REBL-distro/wiki/REBL-and-nREPL
:nREPL {:extra-deps {nrepl/nrepl {:mvn/version "0.6.0"}}}}}
@joinr
joinr / demo.clj
Last active January 3, 2021 19:57
aoc2020-23
(ns aoc2020.demo)
(def demo [3 8 9 1 2 5 4 6 7])
;;transcribed from https://www.youtube.com/watch?v=5AqX3Wu00ok
(defn cups->circle ^longs [cups-prefix ^long total-cups]
(let [circle (long-array (inc total-cups))]
(doseq [[a b] (partition 2 1 cups-prefix)]
(aset-long circle a b))
@joinr
joinr / tbench.clj
Created October 15, 2020 08:43
transient microbench
(require '[criterium.core :as c])
(c/quick-bench
(reduce (fn [acc k] (assoc acc k k)) {} (range 10000)))
;;Execution time mean : 1.682198 ms
(c/quick-bench
(persistent!
(reduce (fn [acc k] (assoc! acc k k)) (transient {}) (range 10000))))
@joinr
joinr / data.txt
Created September 21, 2020 08:13
random data
AC-Supply RC-Supply Total color
0 1 0.045520739 0
0 2 0.071107953 0
0 3 0.150327472 0
0 4 0.192504721 0
0 5 0.221096196 0
0 6 0.267587869 0
0 7 0.319542007 0
0 8 0.366750742 0
0 9 0.367490051 0
@joinr
joinr / rrbtest.clj
Created August 25, 2020 08:58
rrb-vector micro benches
(ns rrbtest.core
(:require [criterium.core :as c]
[clojure.core.rrb-vector :as fv]))
(let [v (vec (range 1000000))]
(c/quick-bench (reduce (fn [_ _] nil) nil v)))
;; Evaluation count : 72 in 6 samples of 12 calls.
;; Execution time mean : 8.588929 ms
;; Execution time std-deviation : 158.450269 µs
@joinr
joinr / correlation.clj
Last active August 13, 2020 19:55
revised correlation
;;These mods pulled runtime down about 37x without going into primitive arrays,
;;and retaining a good bit of the original code.
;;Intermediate mods that got us down about 12x, keeping fairly clost to the original.
#_(defn split-adjacent [f xs]
(let [prev (atom nil)
res (reduce (fn [acc x]
(if (f x)
(reset! prev x)
@joinr
joinr / pizza.clj
Created August 3, 2020 20:19
of types and pizza
(ns pizza
(:require [clojure.spec.alpha :as s]))
(s/def :order/id int?)
(s/def :order/status #{:received :delivered :cancelled})
(s/def :pizza/kind #{:plain :pepperoni :hawaiian})
(s/def ::pizza-order (s/keys :req [:order/id :order/status :pizza/kind]))
;;pack some "type" into the data
(def my-pizza-order
@joinr
joinr / changes.clj
Last active July 2, 2020 16:25
Disabled GIL checks with debugging
;;added libpython-clj.python.logging require to libpython-clj.jna.base
(defmacro def-pylib-fn
[fn-name docstring rettype & argpairs]
`(defn ~fn-name
~docstring
~(mapv first argpairs)
(log-info (str [:skipping-GIL-check!
{:name ~fn-name
:thread (current-thread-id)
:gil-thread (.get ^AtomicLong gil-thread-id)}]))