Skip to content

Instantly share code, notes, and snippets.

View patte's full-sized avatar

Patrick Recher patte

View GitHub Profile
@patte
patte / create_date_xmps.ugly.sh
Created November 1, 2025 16:46
write .xmp with DateTimeOriginal for files which miss creation date based on Library.apdb extraction and file creation date
#!/usr/bin/env bash
## move away CR2 and AAE files
cd /data/
SRC="./Fotos-Mediathek.photoslibrary/Masters/"
DEST="./additional-files/Masters/"
sudo mkdir -p "$DEST"
sudo rsync -av \
--remove-source-files \
@patte
patte / simulate_zfs_data_errors.md
Last active October 31, 2025 18:14
test zed notifications by manufacturing a bad zfs scrub
# create
dd if=/dev/zero of=/tmp/sparse_file bs=1 count=0 seek=512M
sudo losetup /dev/loop10 /tmp/sparse_file
sudo zpool create test /dev/loop10
sudo zpool status test

# write
sudo zfs create test/fs
sudo dd if=/dev/urandom of=/test/fs/bigfile bs=1M count=400 status=progress
@patte
patte / linux_mail.md
Last active October 31, 2025 17:40
setup email sending on linux
sudo apt install --no-install-recommends msmtp msmtp-mta bsd-mailx

sudo touch /var/log/msmtp
sudo chown root:users /var/log/msmtp
sudo chmod 664 /var/log/msmtp

echo 'set mta=/usr/bin/msmtp' | sudo tee -a /etc/mail.rc

sudo vi /etc/msmtprc
# fix for:
# perl: warning: Setting locale failed.
# perl: warning: Please check that your locale settings:
# LANGUAGE = (unset),
# LC_ALL = (unset),
# LC_CTYPE = "UTF-8",
# LANG = "C.UTF-8"
# are supported and installed on your system.
# perl: warning: Falling back to a fallback locale ("C.UTF-8").
@patte
patte / buffers.ts
Last active September 23, 2025 13:56
fix: Argument of type 'Uint8Array<ArrayBufferLike>' is not assignable to parameter of type 'Uint8Array<ArrayBuffer>'
/**
* Asserts that the provided Uint8Array is backed by an ArrayBuffer.
*
* Throws an error if the buffer is a SharedArrayBuffer or any other type.
* This is useful for ensuring (type) compatibility with APIs that require Uint8Array<ArrayBuffer>.
* Usage:
* // bytes: Uint8Array<ArrayBufferLike>
* assertArrayBuffer(bytes);
* // bytes: Uint8Array<ArrayBuffer>
*
@patte
patte / led.service
Created August 28, 2025 13:13
Turn off the LED of the powerbutton on framework notebooks.
# /etc/systemd/system/led.service
[Unit]
Description=Turn off boot button LED
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c "echo 0 > /sys/class/leds/chromeos:white:power/brightness"
RemainAfterExit=true
User=root
@patte
patte / proxy_server.go
Created February 15, 2024 11:39
litefs proxy_server.go with simple websocket support
package main
import (
"io"
"log"
"net/http"
"net/http/httputil"
"net/url"
)
var topojsonClient = require("topojson-client")
ch = await fetch("https://swiss-maps.vercel.app/api/v0?format=topojson&projection=wgs84&year=2022&shapes=lakes").then(res => res.json())
geo = topojsonClient.feature(ch, ch.objects.lakes)
console.log(JSON.stringify(geo, null, 2))
@patte
patte / Logitech G502 X.md
Last active November 6, 2022 02:02
Logitech G502 X (HID, hidraw)
@patte
patte / wireguard-allowedips-exclude.md
Created April 1, 2021 20:49
exclude one address from Wireguard AllowedIPs

exclude one address from Wireguard AllowedIPs

The following python script calculates the network addresses in CIDR notation (ready to be set in the config to AllowedIPs =) to route all traffic (0.0.0.0/0) except for one address (30.31.32.33/32) through the wireguard interface. This is usefull if you run wireguard over another tunnel (e.g. udp2raw).

$ python3

import ipaddress
n1 = ipaddress.ip_network('0.0.0.0/0')
n2 = ipaddress.ip_network('30.31.32.33/32')
l = list(n1.address_exclude(n2))