Skip to content

Instantly share code, notes, and snippets.

@wotbrew
wotbrew / reference_site_memoization.clj
Last active January 12, 2026 19:21
reference_site_memoization.clj
(ns reference-site-memoization
(:require [malli.core :as m]))
(let [reg (merge (m/default-schemas)
;; not quite minimal yet, it is a mini version of the kind of expr trees we have
{::Int :int
::String :string
::Call [:and
[:fn vector?]
[:multi {:dispatch first}
@wotbrew
wotbrew / broadcast.md
Last active February 27, 2025 13:59
broadcast.clj

Type-Specialized Array Broadcasting in Clojure

This proposal introduces macros for broadcasting functions over arrays with automatic type specialization. These macros efficiently bind a set of parameters, which may be either scalars or 1D arrays. While extending this to N-dimensional arrays is possible, my focus is on 1D arrays.

Core Concept

(broadcast-fn [x y z] (+ x y z))
(broadcast-fn! [x y z] (set! z (+ x y)))
@wotbrew
wotbrew / mysql.clj
Created December 14, 2020 15:59
mysql helpers
(ns riverford.mysql
"Working with next.jdbc can be a bit onerous, particularly as it is compatible with multiple
databases.
Here are some helper functions that make working with mysql databases a bit easier.
This module uses next.jdbc, expect qualified keys, datafy/nav and so on."
(:require [clojure.string :as str]
[honeysql.format :as honey]
[next.jdbc :as n.jdbc]
@wotbrew
wotbrew / better_now.clj
Last active August 29, 2015 14:22
using an executor like a reasonable human being
(defrecord Err [exc])
(defn error?
"Is the value an `Err`"
[v]
(instance? Err v))
(defn work-request
[f executor]
(let [o (async/chan)]
@wotbrew
wotbrew / async_executor.clj
Created June 4, 2015 15:37
JUST USE AN EXECUTOR
(ns async-executor.core
"Basic fixed 'task executors' and request-response using core.async")
(defrecord Err [exc])
(defn error?
"Is the value an `Err`"
[v]
(instance? Err v))
@wotbrew
wotbrew / hashsplit.clj
Created June 4, 2015 14:56
core async hash partitioning
(defn hash-split
"Returns a vector containing 1 channel per bucket. (`buckets` being a positive integer)
will spawn a process that reads from `ch` and partitions each value into
a channel decided by the .hashCode of `(key v)`, so that items sharing the same hash
will arrive in the same channel in their insertion order.
This enables parallism via the resultant channels while enabling write order
consistency for items sharing a key.
The result channels will close when the input closes. If an output channel is closed
(defn zip-longest
"Takes 2 sequences and zips the sequences together
however, instead of zipping until one of the sequences is exhausted
will cycle the shorter sequence - therefore returning a sequence as
long as the longest collection
e.g (zip-longest ['a 'b 'c 'd] [1 2])
=> (['a 1] ['b 2] ['c 1] ['d 2])"
[coll1 coll2]
(let [length (max (count coll1) (count coll2))]
@wotbrew
wotbrew / async-chunked.clj
Last active August 29, 2015 14:22
core.async timed flushing partition fn
(defn chunked!
"Returns a channel that will contain vectors of n items taken from ch. The
final vector in the return channel may be smaller than n if ch closed before
the vector could be completely filled.
However if flush-time elapses any buffered input will be flushed onto the return channel.
The output channel is unbuffered by default, unless buf-or-n is given"
[in out n flush-time]
(go-loop
@wotbrew
wotbrew / gist:11214052
Created April 23, 2014 12:51
full immutant error pub
13:27:42,314 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-16) MSC00001: Failed to start service jboss.deployment.unit."xxx.clj".STRUCTURE: org.jboss.msc.service.StartException i
n service jboss.deployment.unit."xxx.clj".STRUCTURE: JBAS018733: Failed to process phase STRUCTURE of deployment "xxx.clj"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:127) [jboss-as-server-7.2.x.slim.incremental.16.jar:7.2.x.slim.incremental.16]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_40]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_40]
at java.lang.Threa
@wotbrew
wotbrew / gist:9961425
Created April 3, 2014 19:41
deps tree
Possibly confusing dependencies found:
[leiningen "2.1.2"] -> [leiningen-core "2.1.0"] -> [com.cemerick/pomegranate "0.2.0"] -> [org.sonatype.aether/aether-connector-wagon "1.13.1"] -> [org.codehaus.plexus/plexus-utils "2.0.7"]
overrides
[leiningen "2.1.2"] -> [leiningen-core "2.1.0"] -> [com.cemerick/pomegranate "0.2.0"] -> [org.apache.maven.wagon/wagon-provider-api "2.2"] -> [org.codehaus.plexus/plexus-utils "3.0"]
and
[leiningen "2.1.2"] -> [leiningen-core "2.1.0"] -> [org.apache.maven.wagon/wagon-http "2.4"] -> [org.apache.maven.wagon/wagon-provider-api "2.4"] -> [org.codehaus.plexus/plexus-utils "3.0.8"]
and
[leiningen "2.1.2"] -> [leiningen-core "2.1.0"] -> [com.cemerick/pomegranate "0.2.0"] -> [org.apache.maven.wagon/wagon-http "2.2"] -> [org.apache.maven.wagon/wagon-provider-api "2.2"] -> [org.codehaus
.plexus/plexus-utils "3.0"]
and