Clojure: persistent do once

Some business requirements require you to only do something once. An example of this would be sending a daily email to users. You could achieve this by making sure you run the function only once per day. However, if that function were to crash part way through how would you know which users had already been sent their daily email and which hadn't? Resolving this without sending some users multiple messages could be a large time sink. A more robust solution would be to make the email sending function idempotent. In this case meaning the effects of the function are applied only once per user per day and any additional applications do nothing. This article will explore one approach to solving this problem in Clojure.

Clojure: permutations

I was solving an Advent of Code problem and part of the solution required generating all the permutations of a set of numbers. Permutation is the act of arranging the members of a set into different orders. I wanted to write a recursive solution rather than an imperative solution. After some searching I found a Scheme) implementation. As Scheme and Clojure are both dialects of Lisp translating one into the other shouldn't be too difficult.

Ruby: functional programming

In one of my previous jobs I worked as a full stack engineer on a codebase with a Ruby backend and a Javascript/React frontend. Having used Clojure a fair bit in my spare time I was keen to code in a functional style. At first glance this seems tricky in Ruby as it doesn't have first class functions.

Clojure: flattening key paths

This article will cover how to flatten the nested key paths of a map in Clojure. Turning a nested map like {:a {:b {:c {:d 1} :e 2}}} into a flat map like {:a-b-c-d 1 :a-b-e 2}.

Clojure: sorting tuples

A tuple is a finite ordered sequence of elements. A common use of tuples in Clojure is for representing pairs of data that are related. For example a key and a value when mapping over a map (hashmap/dictionary). That being said tuples can be of any length, and are a common way of representing larger sets of related data in languages that don't use maps as prolifically as Clojure. This articles explores sorting tuples in Clojure.

Clojure: generating HTML and XML

HTML and XML are ubiquitous, whether it's the pages of a static site or configuration for a logger, being able to programmatically generate these files can be really powerful. This article will cover how to generate HTML and XML files in Clojure.

Clojure: using java.time with clojure.java.jdbc

Java 8 introduced java.time to replace the existing java representations of time java.util.Date, java.sql.Timestamp etc. There were many problems with this old implementation: it wasn't thread safe, it had a clunky API and no built in representation for timezones. java.time is the successor to the fantastic joda.time project which solves all these problems. So if java.time fixes everything then why this article? Well, java.sql.Timestamp still rears its ugly head at the database layer where it is still the default representation of time in the java.jdbc database drivers. In this article we will cover how to automate the conversion between java.sql.Timestamp and java.time so you never have to deal with java.sql.Timestamp again.

Clojure: connection pooling with hikari-cp

Connection pooling is a technique for improving app performance. A pool (cache) of reusable connections is maintained meaning when users connect to the database they can reuse an existing connection. When the user finishes using the connection it is placed back in the pool for other users to use. This reduces the overhead of connecting to the database by decreasing network traffic, limiting the cost of creating new connections, and reducing the load on the garbage collector. Effectively improving the responsiveness of your app for any task that requires connecting to the database.

Clojure: emoji in strings

Sometimes your problem domain requires the use of emoji. This article will cover how emoji are represented in Clojure strings.