Skip to content

Instantly share code, notes, and snippets.

View mpenet's full-sized avatar
🪲
breeding bugs

Max Penet mpenet

🪲
breeding bugs
View GitHub Profile
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.12.0-alpha1"}}}

Old but still relevant, and since innoq link-rots.

Jarkko Oranen a.k.a. Chousuke posted an excellent table summarizing the performance characteristics of functions operating on different Clojure data structures:

disj--near-constantlogarithmic----
hash-mapsorted-maphash-setsorted-setvectorqueuelistlazy seq
conjnear-constantlogarithmicnear-constantlogarithmicconstant (tail)constant (tail)constant (head)constant (head)
assocnear-constantlogarithmic--near-constant---
dissocnear-constantlogarithmic------
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt install build-essential libgtk-3-dev libgnutls28-dev libtiff5-dev libgif-dev libjpeg-dev libpng-dev libxpm-dev libncurses-dev texinfo \
libjansson4 libjansson-dev \
libgccjit0 libgccjit-11-dev gcc-11 g++-11
./autogen.sh
export CC=/usr/bin/gcc-11 CXX=/usr/bin/gcc-11
./configure --with-native-compilation --with-json --with-pgtk
make -j8
sudo make install
(defn allowed-keys?
[ks]
#(set/superset? ks (set (clojure.core/keys %))))
(defmacro keys
"Like clojure.spec.alpha/keys but allow to pass a `:closed?` parameter
to make the spec strict on allowed keys."
[& {:keys [closed? req req-un opt opt-un _gen] :as args}]
(let [keys-form `(s/keys ~@(apply concat args))]
(if closed?
(defun cljfmt ()
(interactive)
(async-shell-command "lein cljfmt fix && echo 'done'"
"*cljfmt-output*"
"*cljfmt-err*"))
@mpenet
mpenet / fs.clj
Last active October 19, 2020 07:10
copy.clj
(defn copy!
[src dest]
(with-open [src-input (FileInputStream. (io/file src))
dest-output (FileOutputStream. (io/file dest))
src-ch (.getChannel src-input)
dest-ch (.getChannel dest-output)]
(let [size (.size src-ch)]
(loop [position 0]
(when (< position size)
(recur (unchecked-add position
@mpenet
mpenet / layer0.json
Last active October 7, 2020 08:03
keeboard.io atreus config
{
"keymap": [
{
"keyCode": 20,
"label": "Q"
},
{
"keyCode": 26,
"label": "W"
},
(defun kikoo-line (nick)
(let ((front (+ (random 13) 1))
(back (+ (random 13) 1)))
(while (= back front)
(setq back (+ (random 13) 1)))
(erc-send-message
(apply 'concat
(append (list (format "\002\003%s,%sKIKOO"
front
back))
(clojure.spec.alpha/def ::asd (clojure.spec.alpha/keys :req [::foo]))
(clojure.spec.alpha/valid? ::asd {})
false
(clojure.spec.alpha/valid? ::asd {::foo 1})
true
;; ::foo was never declared
(defn deterministic-sampler
[rate]
(let [bound (Integer/divideUnsigned -1 rate)] ;; -1 as int is 0xffffffff
(fn [s]
(pos? (Integer/compareUnsigned bound (hash s))))))