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

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------
@borkdude
borkdude / gen-deps.clj
Last active August 9, 2024 09:56
Gen deps.edns in mono-repo using babashka script. Merge default dep versions.
#!/usr/bin/env bb
(ns update-deps
(:require [clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.pprint :as pp :refer [pprint]]
[clojure.walk :as walk]))
(defn- merge-defaults [deps defaults]
(let [ff (some-fn deps (complement (partial contains? deps)))
(defonce ^Logger logger (doto (Logger/getLogger "clojure")
(.setUseParentHandlers false)
(.addHandler
(doto (ConsoleHandler.)
(.setLevel Level/ALL)
(.setFormatter
(proxy [SimpleFormatter] []
(format [^LogRecord record]
(let [sb (StringBuilder.)]
(.append sb "#:log{")
@eihli
eihli / weighted_rand.clj
Created October 23, 2020 18:29 — forked from ghadishayban/weighted_rand.clj
Vose's alias method for weighted randoms
(ns weighted-rand
(:import clojure.lang.PersistentQueue))
(defprotocol Rand
(nextr [_ rng]))
;; Vose's alias method
;; http://www.keithschwarz.com/darts-dice-coins/
(deftype Vose [n ^ints alias ^doubles prob]
(ns deployer
(:require [clojure.tools.deps.alpha :as deps]
[clojure.tools.deps.alpha.reader :as reader]
[clojure.java.io :as io]
[clojure.string :as string])
(:import (java.security MessageDigest)
(com.jcraft.jsch JSch)
(java.net URI)))
(def hex-alphabet (vec "0123456789ABCDEF"))
@reborg
reborg / conference-radar.md
Last active January 28, 2019 17:56
Conference Radar
@mpneuried
mpneuried / postgres_add_json_sub_array_unique.sql
Last active July 12, 2024 11:47
Add and remove elements unique to a Postgres jsonb sub key: Short a Set implemetation
UPDATE public.mytable SET
jsonfieldname = jsonb_set( jsonfieldname, '{json_obj_key}', array_to_json(
ARRAY(
SELECT DISTINCT( UNNEST( ARRAY(
SELECT json_array_elements_text( COALESCE( jsonfieldname::json->'json_obj_key', '[]' ) )
) || ARRAY['Element to add'] ) )
)
)::jsonb )
WHERE id = 23
RETURNING *;
@frenchy64
frenchy64 / bash_profile.sh
Created July 19, 2017 13:55
Update clojure spec alpha
update_spec_alpha () {
git grep -l clojure.spec | xargs sed -i '' 's/clojure.spec /clojure.spec.alpha /g'
git grep -l clojure.spec | xargs sed -i '' 's/clojure.spec.test /clojure.spec.test.alpha /g'
git grep -l clojure.spec | xargs sed -i '' 's/clojure.spec.gen /clojure.spec.gen.alpha /g'
}
;; differences from scheme unfold
;; even initial value is lazy
;; predicate sense reversed
;; internal state == produced value, no special mapper-fn
;; no tail-gen
(defn series
"Produces a sequence of values.
`f` is a function that given a value, returns the next value.
`continue?` is a predicate that determines whether to produce
@ikitommi
ikitommi / Proposal.md
Last active March 4, 2024 01:49
Specs & Schema for Clojure web apps

Specs & Schema for Clojure web apps

Common ground for different modelling libs (Spec, Schema, ...) for web usage.

Additional metadata on models

  • for Schema, there are multiple ways to add extra metadata (at least in ring-swagger, schema-tools and in compojure-api)
  • emerging tools for spec
  • could have a common model
    • less syntax to learn