I started playing the NYTimes word game “Connections” recently, by the recommendation of a few friends. It has the type of freshness that Wordle lost for me a long time ago. After playing Connections for a few days, I wondered if an OpenAI language model could solve the game (the objective is to group the 16 words into 4 categories of 4 words). I tried with gpt-4-32k and gpt-4-1106-preview, tweaking prompts for a few hours and wasn’t able to make much progress. It’s certainly possible prompt engineering alone could solve this problem, but it wasn’t easy for me for find a path forward. I imagine it will involve a bit of creativity. I decided this was as good a time as any to try and fine tune a model to do a thing I couldn’t easily get it to do with prompts.

Goku has a concept called a simlayer. A simlayer allows you to press any single key on the keyboard, then any second key while holding the first and trigger an arbitrary action as a result. I’m going to write a karabiner.edn config that opens Firefox when you press .+f.

{:simlayers {:launch-mode {:key :period}},
 :templates {:open-app "open -a \"%s\""},
 :main
 [{:des "launch mode",
   :rules [:launch-mode [:f [:open-app "Firefox"]]]}]}
❯ goku
Done!

To start, we define a simlayer for the period key. We will reference this layer when we define our rules. Next we define a template. Each entry in :templates is a templated shell command that can run when a rule is satisfied. Finally, we define the “launch mode” rule in :main. We can call it anything we want, so I chose “launch mode”. Now let’s breakdown the rule

Karabiner is a keyboard customizer for macOS. I’ve used it for a while to map my caps lock key to cmd + ctrl + option + shift. This key combination is sometimes called a hyper key. With this keyboard override, I use other programs like Hammerspoon and Alfred to do things like toggle apps and open links. Karabiner provides an out-of-the-box, predefined rule to perform this complex modification. I’ve used this approach for a while but recently learned about Goku which adds a lot of additional functionality to Karabiner using Clojure’s extensible data notation (edn) to declaratively configure Karabiner.

I’ve starting playing around with Fireworks.ai to run inference using open source language models with an API. Fireworks’ product is the best I’ve come across for this use case. While Fireworks has their own client, I wanted to try and use the OpenAI Python SDK compatibility approach, since I have a lot of code that uses the OpenAI SDK. It looks like Fireworks’ documented approach no longer works since OpenAI published version 1.0.0. I got this error message:

At the beginning of 2023, I set some goals for myself. Here are those goals and how the year turned out.

Learn a new word each week (50%)

Clear and effective communication is important to me. My thought process was that I could improve as a communicator if I further developed my vocabulary. I also find it particularly satisfying to conjure the perfect word to describe a situation, experience, etc. Each Monday, I would find a new word and record it, it’s part of speech and definition in Obsidian. Periodically, throughout the week, I would review the new word and all previous words using spaced repetition. This approach was relatively effective at first, but not so effective over the year. In total, I learned 24 new words. About halfway through the year, I would get a reminder on Monday to add a new word to the list, and the timing was bad. I would put it off, then I fell behind and never caught back up. I could have changed up when I scheduled this reminder, but I didn’t. I’m not sure if I will try something like this again. I like the prospect of learning new words, but I think I’d prefer to do so less is a rote memorization kind of way and more in a “search and discover cool words” kind of way.

In a previous note, I discussed running coroutines in a non-blocking manner using gather. This approach works well when you have a known number of coroutines that you want to run in a non-blocking manner. However, if you have tens, hundreds, or more tasks, especially when network calls are involved, it can be important to limit concurrency. We can use a semaphore to limit the number of coroutines that are running at once by blocking until other coroutines have finished executing.

Python coroutines allow for asynchronous programming in a language that earlier in its history, has only supported synchronous execution. I’ve previously compared taking a synchronous approach in Python to a parallel approach in Go using channels. If you’re familiar with async/await in JavaScript, Python’s syntax will look familiar. Python’s event loop allows coroutines to yield control back to the loop, awaiting their turn to resume execution, which can lead to more efficient use of resources. Using coroutines in Python is different from JavaScript because they can easily or even accidentally be intermingled with synchronously executing functions. Doing this can produce some unexpected results, such as blocking the event loop and preventing other tasks from running concurrently.

Render is a platform as a service company that makes it easy to quickly deploy small apps. They have an easy-to-use free tier and I wanted run a Python app with dependencies managed by Poetry. Things had been going pretty well until I unexpectedly got the following error after a deploy

Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

You don’t have to search for too long to find out this isn’t good. I tried changing the PYTHON_VERSION and POETRY_VERSION to no avail. I also read a few threads on community.render.com. With nothing much else I could think of trying, I happened to find the Clear build cache & deploy sub-option under Manual Deploy. Fortunately for me, running that fixed my issue. Hopefully, this helps save someone time.

In Javascript, using async/await is a cleaner approach compared to use of callbacks. Occasionally, you run into useful but older modules that you’d like to use in the more modern way.

Take fluent-ffmpeg, a 10 year old package that uses callbacks to handle various events like start, progress, end and error.

Using callbacks, we have code that looks like this:

const ffmpeg = require('fluent-ffmpeg');

function convertVideo(inputPath, outputPath, callback) {
  ffmpeg(inputPath)
    .output(outputPath)
    .on('end', () => {
      console.log('Conversion finished successfully.');
      callback(null, 'success'); // Pass 'success' string to callback
    })
    .on('error', (err) => {
      console.error('Error occurred:', err);
      callback(err);
    })
    .run();
}

// Usage of the convertVideo function with a callback to receive 'success' string
convertVideo('/path/to/input.avi', '/path/to/output.mp4', (error, result) => {
  if (!error && result === 'success') {
    console.log('Video conversion completed:', result);
  } else {
    console.log('Video conversion failed:', error);
  }
});

Using a promise, we use async/await as well:

When deploying software with Kubernetes, you need to expose a liveness HTTP request in the application. The Kubernetes default liveness HTTP endpoint is /healthz, which seems to be a Google convention, z-pages. A lot of Kubernetes deployments won’t rely on the defaults. Here is an example Kubernetes pod configuration for a liveness check at <ip>:8080/health:

apiVersion: v1
kind: Pod
metadata:
  name: liveness-http
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/liveness
    args:
    - /server
    livenessProbe:
      httpGet:
        path: "/health"
        port: 8080
      initialDelaySeconds: 3
      periodSeconds: 3

When setting up a new app to be deployed on Kubernetes, ideally, the liveness endpoint is defined in a service scaffold (this is company and framework dependent), but in the case it isn’t, you just need to add a simple HTTP handler for the route configured in the yaml file. In an express app, it could look something like this: