Skip to content

Instantly share code, notes, and snippets.

@stbuehler
stbuehler / track-schema-renames.py
Created May 22, 2024 16:48
postgres: track renamed constraints and indices using apgdiff
#!/usr/bin/env python3
# track CONSTRAINT and INDEX renames for ALTER statement.
# uses [`apgdiff``](https://www.apgdiff.com/)
import dataclasses
import re
import subprocess
# create old and new schema exports with: `pg_dump -sxO dbname > schema.sql`
CREATE OR REPLACE PROCEDURE upgrade_serial_to_identity(tbl regclass, col name)
LANGUAGE plpgsql
AS $$
DECLARE
colnum smallint;
count int;
maxval int;
cmd text;
r RECORD;
BEGIN
@stbuehler
stbuehler / debug_fcntl_setlk.c
Created July 15, 2023 16:37
fcntl_setlk_bcc_trace
#include <uapi/linux/ptrace.h>
#include <linux/sched.h>
#include <linux/fcntl.h>
#include <linux/fs.h>
#include <linux/path.h>
#include <linux/dcache.h>
#include <linux/limits.h>
@stbuehler
stbuehler / fcntl_setlk.bt
Created July 15, 2023 12:17
debug fcntl F_SETLK[W] with bpftrace
#include <fcntl.h>
/* Usage example: bpftrace fcntl_setlk.bt podman */
kretfunc:vmlinux:fcntl_setlk / $# == 0 || comm == str($1) / {
if (args->flock->l_type == F_UNLCK) {
delete(@pending_locks[pid, args->filp])
} else if (retval == 0) {
@pending_locks[pid, args->filp] = 1
}
@stbuehler
stbuehler / scrot-xclip.sh
Created September 24, 2021 07:36
scrot to clipboard with automatic cleanup
#!/bin/sh
# example config for i3 (.config/i3/config):
# # select window with mouse
# bindsym Print exec --no-startup-id scrot-xclip.sh --select --freeze
# # current window
# bindsym $mod+Print exec --no-startup-id scrot-xclip.sh --focused
set -e
@stbuehler
stbuehler / smb-versions.txt
Created August 11, 2020 13:47
Windows/Samba internal versions
major | minor | build | type | mainstream | extended | name
10 | 0 | 19645 | desktop | | | Windows 10 Insider Preview Build 19645 (2020-06-10)
10 | 0 | 19640 | desktop | | | Windows 10 Insider Preview Build 19640 (2020-06-03)
10 | 0 | 19635 | desktop | | | Windows 10 Insider Preview Build 19635 (2020-05-28)
10 | 0 | 19603 | desktop | | | Windows 10 Insider Preview Build 19603 (2020-04-08)
10 | 0 | 19551 | desktop | | | Windows 10 Insider Preview Build 19551 (2020-01-23)
10 | 0 | 19536 | desktop | | | Windows 10 Insider Preview Build 19536 (2019-12-16)
10 | 0 | 19041 | desktop | 2021-12-14 | none | Windows 10 (version 2004)
10 | 0 | 18363 | server | 2021-05-11 | TBA | Windows Server (version 1909)
10 | 0 | 18363 | desktop | 2022-05-10 | none | Windows 10 (version 1909)
@stbuehler
stbuehler / livecd-repair-rootfs-interactive.sh
Last active December 27, 2021 16:22
mount rootfs from livecd to repair grub / ...
# Find block device names for main disk, rootfs and /boot (if it is on a separate partition; usually with encrypted rootfs)
# your main disk isn't necessarily /dev/sda anymore; NVMe disks have names like /dev/nvme0n1
# -> /dev/sda might as well be the "livecd"
# For UEFI boot you should also identify the EFI partition; EFI requires a gpt PTTYPE.
lsblk -p -o NAME,RM,SIZE,RO,PTTYPE,TYPE,FSTYPE,MOUNTPOINT,LABEL,PARTLABEL
# or use `lsblk -p; blkid` instead of the long lsblk command
# If you run mdadm raid, probably should start with that. Instructions not included (yet).
# If encrypted rootfs: open it
cryptsetup open /dev/${cryptpart} ${cryptpart}_crypt
@stbuehler
stbuehler / create-ldap-ssha.sh
Created July 1, 2020 09:23
create ldap {SSHA} (salted sha1) password hashes
#!/bin/bash
tmpdir=$(mktemp --tmpdir -d create-ldap-ssha-XXXXXXX)
trap 'rm -rf "${tmpdir}"' EXIT
openssl rand -out "${tmpdir}/salt" 8
echo -n "Enter password: "
read -rs password
echo
@stbuehler
stbuehler / with-cap-as-user.sh
Created June 11, 2020 13:24
run a given command (or the login shell) with additional capabilities as a normal user.
#!/bin/bash
# Start as root; run a given command (or the login shell) with additional capabilities as a normal user.
# Eg: with-cap-as-user.sh +net_bind_service -u myhttpuser -- nc -l -p 80
caps=
user=
keepenv=0
@stbuehler
stbuehler / README.md
Last active January 27, 2020 08:25
corretto-jdk repo builder

Build debian repo for corretto jdk

Provides a debian repo for corretto jdk (8, but can be modified for 11).

Also provides an "archive" of all older versions.

Needs

  • reprepro
  • wget