Skip to content

Instantly share code, notes, and snippets.

@bsless
bsless / burrito.clj
Created March 1, 2020 15:44
Emit lojure code to
(defn camel->snake
[s]
(-> s
(clojure.string/replace #"([^_A-Z])([A-Z])" "$1-$2")
clojure.string/lower-case))
(defn gen-param*
[c]
(->
c
@bsless
bsless / split.clj
Created February 17, 2020 07:15
All the ways to split a sequence in two based on a predicate
(ns clj-seperate-bench.core
(:gen-class)
(:require
[criterium.core :as c]))
;;; Run with:
;;; java -Xmx8G -Xms8G -XX:+UseG1GC -jar target/uberjar/clj-seperate-bench-0.1.0-SNAPSHOT-standalone.jar
;; 54, 60 ms range
;; 54, 34 ms vector
@bsless
bsless / core-logic-perf-gotcha.md
Last active January 7, 2020 12:48
Small Clojure core.logic performance gotcha

Seems like when using a logic db in core.logic most of the CPU cicles are spent on manipulating the thead bindings the *logic-dbs* dynamic var. However, it is only used as a wrapper when calling the underlying -run macro. Invoking it directly speeds things up significantly

Let's set up some dummy data:

(require
 '[clojure.core.logic.pldb :as pldb]
@bsless
bsless / yt-mpv.el
Created February 5, 2019 10:58
Opening YouTube Links In MPV from Emacs
(defun mpv-play-url (url &rest args)
""
(interactive)
(start-process "mpv" nil "mpv" url))
(setq browse-url-browser-function
(quote
(("youtu\\.?be" . mpv-play-url)
("." . eww-browse-url))))
@bsless
bsless / lambda_on_dict.py
Created November 27, 2018 07:49
Applying lambdas to dictionaries in python
d = dict(a=1, b=2, c=3)
# it really should not be that weird
list(map(lambda k, v: (k, 2*v), *zip(*d.items())))