Finding PID Everywhere

the proc virtual filesystem

Usually at least one of those is present on any system top htop / another top variant ps But sometimes the usual suspects are not available, especially in minimal containers. But there is another, more low level, way that works: /proc This is a virtual filesystem provided by the kernel about running processes. So to mirror something like this: $ ps aux |grep sleep 5 root 0:00 sleep 1000 21 root 0:00 sleep 10000000 36 root 0:00 grep sleep We could do: [Read More]

Hacking Comments Into JSON

JSON does not natively support comments, which is OK, but sometimes a comment could really help. If the application loading the JSON does not care about additional keys we can simply add a key with our favorite comment indicator like // or #. { "//": "This setting enables not just A, but somehow also B", "enable_feature_a": true } Tip While this works consider using a different file format better suited for configuration. [Read More]
json 

Replace item in list with Kustomize

Kubernetes resources have quite a lot of lists in them and replacing an item in such lists is quite easy using kustomize patches with op: replace.

Replacing a specific list item safely however is not as obvious as the order of items could change, leading to a technically valid but practically incorrect manifest.

[Read More]

Easy Backlink Check

There are loads of better ways to do this using Google Search Console / Bing Webmaster Tools / ahrefs and similar tools.

Arguably these might be a bit too much for a small side project or a curious quick check, so this is how I do it. The same syntax works for both Google and Bing.

[Read More]
seo 

Caddy: Custom Domains for SaaS

Building custom domains for your SaaS is not always easy, especially when certificates get involved.

With Caddy it becomes very easy!

[Read More]
caddy 

Oh Shit, Git!?!

Git is hard: screwing up is easy, and figuring out how to fix your mistakes is fucking impossible. Git documentation has this chicken and egg problem where you can’t search for how to get yourself out of a mess, unless you already know the name of the thing you need to know about in order to fix your problem. Oh Shit, Git!?! is a collection of these situations, in plain English, and how to resolve them. [Read More]
git 

Colorize pattern on CLI

Colorize a pattern in the given input using a neat regex and colorization hack in grep ($ matching all lines but not being able to be highlighted).

color () {
  # Color highlight the pattern in the incoming stream, writing to stdout
  # This effectively matches our PATTERN andy any "$" (line end)
  # But only our PATTERN can be highlighted, line end characters aren't actually there to be highlighted
  local PATTERN=$1

  if [ -z "$1" ]; then
    echo "Usage: color <pattern>"
    echo "Description: Greps input with --color=always -E 'PATTERN|\$' "
    echo "Example: echo \"hello world\" | color \"world\""
    return 1

  fi
  grep --color=always "$PATTERN\|\$"
}

kubectx & kubens

When working with multiple Kubernetes clusters and namespaces switching context can be a chore.

For this I enjoy using kubectx and kubens.

They can be installed using kubectl krew.

kubectl krew install ctx
kubectl krew install ns

Tip

I’ve since switched to kubeswitch, which works much nicer for me.

k8s  tools 

Simple Redirect View for Django

I often find myself replacing an existing MVP based on static html with a Django app, or just needing to preserve some old URL scheme.

This is the code I use to do that:

from django.shortcuts import redirect

def redirect_view(request, redirectable, permanent=True):
  return redirect(redirectable)

Which can then be used like this:

from django.urls import path
from . import views

urlpatterns = [
    path("old-url/", views.redirect_view, {"redirectable": "new_view"}),
    path("some-thing/", views.redirect_view, {"redirectable": "some_thing_new", permanent=False}),
]

Cleanup After Script Exit

Many of my scripts work with temporary files, usually relative to the scripts directory1, while at the same time using set -e to exit as soon as something fails.

In this scenario the script leaves behind these temporary files by default, which is not desirable.

We can however do a proper cleanup using the trap concept.

[Read More]

Vault CLI in Containers

In many CI/CD workflows interfacing with Hashicorp Vault is required.

However, their CLI (or better called unified binary1) is stupidly big with more than 400MB and they seem to have no interest in making it any smaller2.

This is often a undesired size increase, especially when optimizing for pull and run time in CI/CD.

This note outlines a solution that brings us down from 400MB+ on disk for vault to about 300KB using curl and jq.

[Read More]

Caddy: Manual Maintenance Mode

Coming from NGINX and others the concept of a maintenance mode that can be manually enabled is something I have used many times before.

With Caddy it is equally as easy, just using a less obvious syntax.

[Read More]