Clojure Projects

24 March 2025

I have a long list of Clojure projects I’ve created over the years to learn Clojure and accomplish various personal tasks.

Advent of Code

As of the end of 2024, I’ve done at least some of Advent of Code for 7 years in a row. I’ve had the most fun and practice parsing and transforming the input data for each puzzle.

I learned pretty quickly from the puzzles to store the common grids as sparse maps to save lots of memory and keep the problem in memory. I sometimes got stuck on the puzzle and the algorithm, but I still got lots of practice in general Clojure. I definitely see that the Clojure data structures lend themselves well to the puzzles. I’ve gotten to effectively apply lots of common Clojure libraries like core.async and core.logic.

Incidents

My incidents project scrapes an RSS feed of emergency response incidents in Lancaster County and stores them into an XTDB database for history. It generates static site of current events with hiccup and historical charts with Clerk.

Running this project day-to-day, I learned that the Clojure/JVM start up is a bit too heavy to start frequently from cron, so I run it as a service in systemd with its own scheduling. Clerk and the amount of data I’m processing is also a bit heavy, so I have that scheduled to rebuild less frequently than the scraper. The site is still all static.

Event Logger

With this CLJS project, I was trying to derive a standard shadow-cljs workflow to make sure I could start any new CLJS web project quickly. It started using Reagent, and I migrated to Helix to be less-insulated from newer React features. I also wrote code to migrate data in local browser storage from an old Transit format to EDN. I’m constantly learning the better flows for data in React and local storage.

COVID Warehouse and COVID Web

The beginning of 2020 provided some of us with lots of downtime, so I started loading and analyzing Johns Hopkins University’s data on COVID with my own data warehouse and web app to display my data.

The data was pretty messy early on, and it changed over time, so I needed to parse lots of different formats. I generated a static site with my historic graphs and focused on World, US, and counties in Pennsylvania. It was a classic ETL for a star schema data warehouse, since I wanted to refresh my experience on that. I initially stored in in a SQL database using hugsql and next.jdbc.

After a bit of time, this became my first project to explore CRUX/XTDB and NoSQL data structures. I learned a bit about how changes applied in XTDB and how to limit history and otherwise save space on my small server environment. I could easily apply core.async when it was time to get things done faster.

The web app project that I added later provided a more dynamic Reagent app in CLJS that used the static data produced by warehouse project.

Planning Poker

I wanted a simple tool for conducting planning poker in sprint planning, so I built one in JS to run on mobile phones. When I started learning CLJS, I converted it to Reagent and used Leiningen to build it.

Clojure All the Other Things!

I’ve enjoyed finding there are ways to apply Clojure to everything!

Structured Intepretation of Computer Programs

Music in Overtone

I have a project where I play with data structures for music and explore lots of examples in Overtone, including Rich Hickey’s experiments in additive synthesis and sequencing some simple beats from drum-n-bass tutorials for other DAWs.

It required lots of yak-shaving work over the years to keep the native wiring to Supercollider and Linux sound working.

3D Objects

I’ve found a library to interface Clojure to OpenSCAD, so I have some 3D models defined in Clojure code for printing.


Fixes for Overtone and SuperCollider on PopOS 20.10

02 November 2020

I took the update to PopOS 20.10, and my Overtone setup stopped working. When I’d try to boot up the internal SuperCollider server from Emacs or from the leiningen repl on my music projects which all (:require [overtone.live :refer :all]), get an error in native libraries. I could also try to start the server with (boot-internal-server) or (boot-external-server), but it gives the same error.

--> Booting internal SuperCollider server...
Cannot read socket fd = 107 err = Success
CheckRes error
Could not read result type = 22
Client name = Overtone conflits with another running client
Cannot connect to the server
JackShmReadWritePtr1::~JackShmReadWritePtr1 - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
could not initialize audio.
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f5eec0e9ba7, pid=30517, tid=30605
#
# JRE version: OpenJDK Runtime Environment AdoptOpenJDK (15.0.1+9) (build 15.0.1+9)
# Java VM: OpenJDK 64-Bit Server VM AdoptOpenJDK (15.0.1+9, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C  [libscsynth.so.1+0x63ba7]  World_WaitForQuit+0x7
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/john/workspace/music/hs_err_pid30517.log
--> Connecting to internal SuperCollider server...
[thread 30576 also had an error]
#
# If you would like to submit a bug report, please visit:
#   https://github.com/AdoptOpenJDK/openjdk-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Since it can no longer start the server internally from within Overtone, I start the server manually. I wrapped a script around the start up, so I can set the environment variables for configuring jack and starting up the synth:

#!/bin/sh

# automatically connect up jack ports
export SC_JACK_DEFAULT_INPUTS="system:capture_1,system:capture_2"
export SC_JACK_DEFAULT_OUTPUTS="system:playback_1,system:playback_2"

scsynth -u 57110

To get Overtone going again, I disabled the automatic boot of the server within Overtone by switching all the requires in each file from overtone.live to overtone.core, and I connect to that external server from my REPL manually with (connect-external-server) before doing anything else.

Finally, Overtone was consistently failing to find my MIDI keyboard. When things were working well enough a couple months ago, it still had required a little dance of killing off jackd and restarting Overtone, since something had been tying up the MIDI interface. This workaround was no longer adequate, since scsynth and jackd needed to already be started. I disabled MIDI connection in jackd by removing the -Xseq option from my ~/.jackdrc.

I’m back in business, and it’s probably more robust with these manual steps now. I think I’m also seeing some other odd little things working with the external server that didn’t previously, like using (mouse-x) for reading mouse positions into the synth values. The built-in piano synth is also working where it hadn’t previously.

Update 2021-02-13: I had lost the ability to send desktop audio (pulseaudio) through to the Jack Sink with this setup, so I figured out to start qjackctl before my supercollider.sh. That gets the Jack Sink available again to pulseaudio and the desktop sound menu.


Escape with Spacemacs in Tmux

21 October 2020

I’ve occasionally been using a SSH session from my Pixel phones for years to login to my servers and write Clojure code in Emacs. I’d often run into an issue where I find myself having a weird time switching between NORMAL and INSERT modes when I’d hit ESCAPE quickly and try to move the cursor.

Googling my random problems is a favorite pastime, and I’ve finally stumbled upon an article about tmux and vim escape key. I learned that it’s probably been tmux sporadically eating my ESCAPE key, so I’ve tried disabling the built-in delay by adding to my .tmux.conf:

set -g -s escape-time 0


Templates and Snippets in Emacs

30 August 2020

I was only trying to write that last article, but it took me days to finally do it. I had so much work to do before I got there.

I had come to appreciate Emacs automatically inserting the boilerplate namespace declarations in new Clojure files, and I really thought I needed such convenience for my blog posts written in AsciiDoc in JBake. I dove down a 20-tab-deep, yak-shaving hole to get it done. [1]

I had to figure out the right search terms and names for what Emacs was doing for me. I finally found yatemplate which seems similar to yasnippets. Spacemacs has the templates layer for integrating yatemplate support, so I added that layer and created a template for my adoc files in my .emacs.d directory. My simple case worked, but I recognized that I’ll want that template on all my machines, so having a local copy of it wouldn’t cut it. I needed a way to check-in and version more Emacs/Spacemacs files than just my ~/.spacemacs files I was previously distributing.

I learned yasnippets would default to looking in ~/.spacemacs.d/ if the configuration was in there, so I had to move my ~/.spacemacs file over to ~/.spacemacs.d/init.el. To have the templates layer source templates from the .spacemacs.d directory, it required an extra bit of configuration when introducing it to the dotspacemacs-configuration-layers:

  (templates :variables templates-private-directory "~/.spacemacs.d/templates")

At this point, I could now commit my .spacemacs.d directory with the regular configuration file and the supporting templates and snippets. All those files will be cloned to all my workstations.

I was almost ready to write that article, but yasnippet and yatemplate have this fancy templating language. I’m sure that can make my article-creation even smarter! I read a bit more and found a couple cool elisp functions for automatically filling in the date and building a title from the file name. With the final enhancements to my adoc template, I could write the article, if I could only remember what I was trying to do in the first place. I hope to at least remember how to use these snippets and templates for future work.


1. I often measure task complexity in the number of tabs I end up having opened.


All the Posts

March 2025

November 2020

October 2020

August 2020