Skip to content

Instantly share code, notes, and snippets.

@divs1210
divs1210 / clj-kondo-conf.md
Last active January 26, 2023 13:33
clj-kondo-lein
# copy libraries' configs
clj-kondo --lint "$(lein classpath)" --dependencies --parallel --copy-configs
;; export current ns types
;; (require '[malli.clj-kondo :as mc])
;; (-> (mc/collect *ns*) (mc/linter-config))
((requiring-resolve 'malli.clj-kondo/emit!))
@divs1210
divs1210 / trampolined-cps.clj
Created December 15, 2022 10:21
Clojure trampolined continuation passing style
(defmacro trampolined
"Wraps recursive calls."
[& body]
`(fn [] ~@body))
(defn trampolined-k-fn
"Takes a k-fn and returns a stackless fn.
k-fn should be a CPS function with k as the first arg.
In k-fn, all recursive calls should be wrapped using `trampolined`."
[k-fn]
@divs1210
divs1210 / eager-cat.clj
Last active December 15, 2022 09:39
Clojure eager concatenation
(defn eager-cat
"Eager concat.
Doesn't blow up the stack.
Returns a vector."
([]
[])
([xs]
(vec xs))
([xs ys]
(into (vec xs) ys))
@divs1210
divs1210 / bfs.clj
Last active November 2, 2022 08:59
Clojure BFS
(defn BFS [tree]
(loop [roots [tree]
ret []]
(if (empty? roots)
ret
(let [children (->> roots
(mapcat :children)
(remove nil?))
this-level (map :val roots)]
(recur children
@divs1210
divs1210 / with-retry.clj
Last active October 17, 2022 16:05 — forked from aphyr/with-retry.clj
Recur from within catch block
(defrecord Retry [bindings])
(defmacro with-retry
"It's really inconvenient not being able to recur from within (catch)
expressions. This macro wraps its body in a (loop [bindings] (try ...)).
Provides a (retry & new bindings) form which is usable within (catch) blocks:
when this form is returned by the body, the body will be retried with the new
bindings."
[initial-bindings & body]
(assert (vector? initial-bindings))
@divs1210
divs1210 / multilambda.py
Last active September 14, 2022 18:14
Dead Simple Multiline Lambdas for Python
def do(*body):
return body[-1]
# Example (Python 2)
# =======
map(lambda x: do(
print('x =', x),
x * x),
range(5))
@divs1210
divs1210 / tinyaprs.js
Created November 26, 2021 14:33
Tinyman APRs
javascript:(function(){
function parseDollarVal(_txt) {
let txt = _txt.split("$")[1] || "0";
let lastChar = txt[txt.length-1];
let multiplier =
lastChar == 'M' ? 1000000
: lastChar == 'K' ? 1000
: 1;
@divs1210
divs1210 / Mylang.md
Last active August 19, 2021 17:52
Hypothetical Programming Language of My Dreams

Mylang

Features

Functional

  • like Clojure / Elixir
  • not fanatic like Haskell

Algol-derived syntax

  • syntax like JS / Python / Ruby / Elixir
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div>
<center>
<h3>Lisp.js</h3>