<p>A small Go function which will return an available port number. The technique is to setup a server bound to port 0, get the port number, then shutdown the server. Not a perfect technique as there’s a tiny race condition between shutting the server down and using the port, but good enough for what I need it for.</p> <figure data-rehype-pretty-code-figure=""><pre tabindex="0" data-language="go"…
<p>For anyone else having trouble installing Netlify CLI in a Github/Forgejo pipeline, seeing the error <code>directory not empty</code> when trying to install Netlify CLI globally, try <a href="https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli/#installation-in-a-ci-environment" class="external">these instructions<svg aria-hidden="true" class="external-icon"…
<p>Today I learnt about the practice of statically asserting that a type in Go implements an interface. This is for cases where you want to guarantee a given type implements an interface, but you’re not in a position to assert this yourself within your own code.</p> <p>An example of this might be to demonstrate a given type implements <code>json.Marshaller</code>. You’re generally not going to…
<p>Whenever I’ve got a database, and an array of IDs, and I want to fetch the rows with those IDs, I tend to favour an <code>in</code> query:</p> <figure data-rehype-pretty-code-figure=""><pre tabindex="0" data-language="sql" data-theme="github-light github-dark"><code data-language="sql" data-theme="github-light github-dark" style="display: grid;"><span data-line=""><span…
<p>Imagine, if you will, a service responsible for dispatching jobs to a pool of workers. The worker reports when a job has started, and will send updated while the job is in progress, and when it’s finished. The dispatcher tracks this in a PostgreSQL database and forwards the completion message upstream. This message should only be sent if the job exists in the database and should only be ever…
<p>A list of techniques for diagnosing and fixing a slowdown caused by PostgreSQL. Some hallmarks for when these techniques could be useful are as follows:</p> <ol> <li><strong>The database CPU is maxing out:</strong> this could be an indication that database is overloaded, either by lots of requests, or a few unoptimised queries. Finding any slow running queries may be a good first step.</li>…