Skip to content

Instantly share code, notes, and snippets.

View robvanderleek's full-sized avatar
💭
👋 Hello Internet

Rob van der Leek robvanderleek

💭
👋 Hello Internet
View GitHub Profile
@robvanderleek
robvanderleek / README.md
Last active April 27, 2024 18:27
Play Asciinema recordings in React

Play Asciinema recordings in React

Asciinema is a great way to share and embed terminal recordings on the web.

Getting started with Asciinema on macOS is as simple as installing the tool with brew install asciinema, and creating a new recording with asciinema rec demo.cast.

There's an NPM package

@robvanderleek
robvanderleek / ducks.py
Created March 29, 2023 13:45
Code Along: Fun with Escape Codes
import random
import time
def clear_screen():
goto_position(1, 1)
print('\033[J', end='')
def goto_position(x, y):
print(f'\033[{y};{x}H', end='')
@robvanderleek
robvanderleek / README.md
Last active March 15, 2023 15:11
When Apple mail gets stuck on "Moving messages"

When Apple mail gets stuck on "Moving messages" 😟

For reasons still unknown my Apple Mail (macOS 13.2) got stuck in an endless "Moving messages" loop. The Internet offers many different solutions to this problem but unfortunately many did not work for me. Until I discoved this page that contained a procedure that did make the "Moving messages" go away.

For future reference, these are the steps:

  1. Exit Apple Mail
  2. Open Finder and go to this folder: ~/Library/Mail/V10/MailData/ (note that I could not access this folder from the terminal)
@robvanderleek
robvanderleek / A-Key.png
Last active January 22, 2023 20:29
Apple Keys
A-Key.png
{
"$schema": "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json",
"basics": {
"name": "Rob van der Leek",
"label": "Senior Software Engineer",
"image": "",
"email": "robvanderleek@gmail.com",
"url": "https://robvanderleek.github.io",
"summary": "Software engineer with over 15 years of industry experience. Feels confident working in greenfield environments and skilled in setting up architectures and development processes from scratch. Loves to work with modern technologies and frameworks, knows the importance of selecting the right tool for the job. Desire to understand the inner workings and the business context of a software product. Software minimalist, is aware of the challenges of long-term maintenance. Strong communicator, both written and spoken.",
"comment-location": {
@robvanderleek
robvanderleek / README.md
Last active November 20, 2021 12:02
Fixing a cascading delete problem in SQLAlchemy

Fixing a cascading delete problem in SQLAlchemy

Recently I spent two days figuring out why a seemingly trivial use of a cascading delete relationship in SQLAlchemy did not work properly, eventually I found the answer in this StackOverflow post. Because it was a real puzzler I've created this short writing, perhaps it can be of help to someone facing the same problem someday.

The context of the problem is very simple: there are two tables (Parent and Child), each Parent can only have one Child and when a Parent row is deleted the associated Child row should also be deleted.

This is how that looks in SQLAlchemy Python code:

class Child(Base):
#!/bin/tcsh
IFS=:
set tempfile=`mktemp`
cat /dev/stdin | figlet -w 999 > $tempfile
set columns=`tput cols`
set spacer_cmd="cat /dev/zero | head -c $columns | tr '\0' ' '"
sed -i.bak "s/^/`$spacer_cmd`/" $tempfile
set banner_length=`cat $tempfile | awk '{print length}' | head -n 1`
set start_index=1
while (1)
#!/bin/bash
IFS=
banner=`cat /dev/stdin | figlet -w 999`
columns=`tput cols`
spacer=`cat /dev/zero | head -c $columns | tr '\0' ' '`
banner_with_spacer=`echo $banner | sed "s/^/$spacer/"`
banner_length=`echo $banner_with_spacer | awk '{print length}' | head -n 1`
start_index=1
while true
do
@robvanderleek
robvanderleek / README.md
Last active March 11, 2024 19:56
AWS SSO command-line login script (that also updates .aws/credentials)

AWS SSO command-line login script (that also updates .aws/credentials)

The AWS Command Line Interface tool from Amazon (for macOS available here on Homebrew) makes it possible to login to AWS through a SSO (Single Sign-On) identity provider such as Okta. However, if you login via "aws sso login" the AWS credentials file (located at ~/.aws/credentials) is not updated, this is a problem for tools/libraries that rely on that file.

This script is a wrapper around aws sso login that also updates the .aws/credentials file. It only requires AWS CLI and Python 3 to run.

Configuration

Make sure your .aws/config file has a section (or multiple sections) that have SSO configuation options. For example:

@robvanderleek
robvanderleek / README.md
Last active January 18, 2024 13:09
Show current Git branch in iTerm2

Show current Git branch in iTerm2

Terminal

If you want your iTerm2 terminal window display the current Git branch (when the current directory is inside a Git repository of course) add the following to your .zshrc:

set_terminal_title() {