This is how I use jq to conditionally add an element to an array only if it doesn’t exist there already. In other words, add an element to an array only if it doesn’t create a duplicate in the array. This is particularly helpful when I’m scripting a JSON transformation and want to make it idempotent.
Programming
Sleep Inside JavaScript Async Function
Typically, the point of a JavaScript async function is to not block execution but occasionally I do want to introduce a delay in an async function (e.g. as part of a delay before retrying a remote call).
unregisterFormatType() for Specific Block Type in Gutenberg
The WordPress block editor (a.k.a. Gutenberg) allows formatting in RichText fields via the Formatting Toolbar API](. Each type of formatting (e.g. Bold and Italic) is a “formatType”. Here we’ll look at removing one of these formatTypes from a specific block type (e.g. removing Bold from the core paragraph block).
PHP class_exists() check without the Fully Qualified Class Name
Sometimes you need to write PHP code that includes a check that the class you want to use exists. Because you need to provide the fully qualified class name (the namespace and the classname) our code can end up looking a little messy – but there is a better way.
Loop Through WordPress Multisite Blogs with WP CLI
When working on a WordPress multisite with WP CLI, it can be helpful to loop through all of the individual sites.
Pure Functions – The Secret to Writing Easily Testable Code
Unit tests are a wonderful tool for programmers. They allow you to ensure an individual part of your code base performs exactly the way you intend. Unit tests are ideal for testing pure functions and therefore it is beneficial to write pure functions.
Replace Local Git Branch with Branch on GitHub
There are times when I want to dispose of my local branch and replace it with the version on GitHub (the upstream version). For example, when I’m reviewing a teammate’s pull request and they rewrite history (e.g. perform a rebase or amend a commit), I don’t have any work on that branch and I only want their updated version.
Is Git Branch Up to Date
I often want to determine if my current Git branch is up to date with some other branch. One specific scenario is when I want to check if my current “feat/” branch is up to date with “main” (i.e. no new commits have been introduced in “main” that aren’t in “feat/”).
Get Jira Issue Title via REST API
I wanted to programmatically retrieve the title of a Jira issue in a script I was working on. These are my notes on how I did it.
Quick and Dirty WP CLI
During development or troubleshooting I often find myself wanting to run something through WP CLI. These are some notes on running code through WP CLI.