Skip to content

Instantly share code, notes, and snippets.

View stigok's full-sized avatar
🚢
ship it!

Stig Otnes Kolstad stigok

🚢
ship it!
View GitHub Profile
@stigok
stigok / timing_resistant.py
Created October 13, 2025 08:53
An attempt to create a decorator for spending at least n seconds before returning from an awaitable/
import asyncio
from functools import wraps
from typing import Any
from collections.abc import Awaitable
def await_at_least(fn: Awaitable[Any], *, seconds: int):
"""
Do not return from the decorated function until at least `seconds`
have passed.
#!/usr/bin/env python3
# ruff: noqa: E501
"""
Given a regular expression pattern containing certain named capture groups,
print a line to stdout for each match found in `infile`. The printed messages
is in a format that will annotate code in a GitHub pull request.
See the source code of this program for usage examples.
See GitHub command reference for more information.
@stigok
stigok / 000001_first.down.sql
Created August 14, 2025 13:04
psql jsonb migration example
-- empty
@stigok
stigok / tfilter
Last active January 13, 2025 12:55
Filter Terraform plan results
#!/usr/bin/env python3
"""
Helper to generate `-target='<resource address>'` arguments to terraform operations
from Terraform output. Operates on text only and does not touch Terraform itself.
Writes output to stdout.
"""
import argparse
import hashlib
import io
import json
@stigok
stigok / README.md
Last active December 30, 2022 11:30
Cheap tmux session manager

Usage

Open a new session, named after the current working directory

$ tat -n

Attach to a named session, or create it if it does not exist

@stigok
stigok / kx
Last active August 26, 2020 14:42
Select active Kubernetes configuration file for the current terminal session
#!/bin/bash
# Select active Kubernetes configuration file for the current terminal session.
#
# Usage:
# - Configure $all_configs variable in this file. It should be a directory
# containing kubectl configuration files.
# - Set $KUBECONFIG to the location of the symbolic link that will be created
# - Run this script
#
# This script is meant to be run using the following alias:
@stigok
stigok / betaling-vipps.py
Last active November 17, 2020 14:02
Betaling med Vipps i Python 3
"""
En enkel demo for å initialisere en Vipps-transaksjon.
Returnerer en URL som kunden kan bruke til å fullføre transaksjonen.
Denne URL kan for eksempel enkodes som en QR-kode og skannes.
Koden er lisensiert som CC-BY
2020 stigok
https://creativecommons.org/licenses/by/4.0/legalcode.no
"""
import datetime
@stigok
stigok / inotify-set-permissions.sh
Last active February 23, 2020 13:43
Automatically set permissions on uploaded files and folders to use in, for example, multi-user FTP environments where different clients set different permissions, or otherwise ignore umask.
#!/bin/bash
# [email protected] Oct 2019
#
# Reference:
# http://positon.org/a-solution-to-the-umask-problem-inotify-to-force-permissions
set -x
# Take the directory name as argument
inotifywait -mrq -e CREATE --format %w%f "$1" | while read FILE
do
@stigok
stigok / mongobackup-s3.sh
Created December 13, 2019 13:03
MongoDB database backup to S3
#!/bin/bash
# Backs up a complete mongodb database instance running on localhost and
# uploads a gzipped dump to an S3 bucket (in this case Scaleway Object Storage)
#
# Configure s3cmd with `s3cmd --configure`
set -eu
MONGODB_USER=${MONGODB_USER}
MONGODB_PASSWORD=${MONGODB_PASSWORD}
@stigok
stigok / nfc.go
Created August 8, 2019 17:47
Golang libnfc read a tag or card with ACR122 reader
// Related blog post:
// https://blog.stigok.com/2019/08/06/golang-with-libnfc-bindings-and-a-acr122u-a9-tag-reader.html
package main
import (
"fmt"
"log"
"github.com/fuzxxl/nfc/2.0/nfc"
)