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 August 20, 2024 12:27
Setting up Basic Auth in FastAPI for endpoints and static files

Setting up Basic Auth in FastAPI for endpoints and static files

Sometimes you want to share something with the world but don't want to have it publicly accessible, and don't want to setup serious authentication like OAuth. In that case, Basic Auth might be just the type of authentication you're looking for.

Setting up basic auth in FastAPI can be done with a just of couple lines of code, but I could not find in the project's documentation how to do it for both endpoints and static files (e.g. a Web App, or plain HTML files).

Based on this discussion I was able to create a minimal implementation that you can find in this repository. Please see the README in the repository how to run and test the setup.

@robvanderleek
robvanderleek / README.md
Last active July 28, 2024 15:45
Reading raw body content on Vercel

Reading raw body content on Vercel

Vercel is a powerful platform for hosting serverless functions. A typical serverless function (in TypeScript) on Vercel looks like this:

async function (request: VercelRequest, response: VercelResponse) {
    response.status(200).json({message: 'hello world'});
}
@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": "",
"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": {
"countryCode": "NL",
@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