Gists

Pastebin nonsense
SMB nspawn

Running SMB share inside an nspawn container, this worked fine, but you're better off chrooting or using libvirt. It's just more straight forward using libvirt and alpine.

# host
sudo apt update
sudo apt install samba samba-common systemd-container

sudo debootstrap --arch amd64 jammy /var/lib/machines/mycontainer

sudo mount -o credentials=$HOME/.smbcredentials,uid=$(id -u),gid=$(id -g),iocharset=utf8 //smb-server/share /mnt/share

sudo machinectl mount mycontainer /mnt/share /mnt/share

# container
sudo systemd-nspawn -D /var/lib/machines/mycontainer --network=host
apt update
apt install samba

# Configure Samba's /etc/samba/smb.conf to expose directories as SMB shares.
# Sample config:
# [share]
#   path = /mnt/share
#   read only = no
#   guest ok = yes

sudo systemd-nspawn -D /var/lib/machines/mycontainer

smbclient //localhost/share -U your_username
Rebalancing BTRFS drives

Had to move a BTRFS pool spread accross multiple disks to a single one. Make sure to go through the docs for rebalancing.

// install btrfs tools if needed
apt install btrfs-progs
# or
dnf install btrfs-progs

// mount existing Btrfs filesystem
mount /dev/sda1 /mnt

// add new, larger disk
btrfs device add /dev/sdc1 /mnt

// rebalance data & metadata into single mode (onto the new drive)
btrfs balance start -dconvert=single -mconvert=single /mnt

// check balance progress
btrfs balance status /mnt

// verify
btrfs device status /mnt
btrfs filesystem show
tree-entry.go patch

Git module maintained by gogs doesn't support showing blob count for a tree item. This is generated from my patch file, used to have a similar patch for libgit2.

// Size returns the size of the entry.
func (e *TreeEntry) Size() int64 {
	e.sizeOnce.Do(func() {
		if e.IsTree() {
			stdout, err := NewCommand("ls-tree", "-l", e.id.String()).RunInDir(e.parent.repo.path)
			if err != nil {
				return
			}
			lines := len(strings.Split(strings.TrimSpace(string(stdout)), "\n"))
			e.size = int64(lines)
			return
		}

		stdout, err := NewCommand("cat-file", "-s", e.id.String()).RunInDir(e.parent.repo.path)
		if err != nil {
			return
		}
		e.size, _ = strconv.ParseInt(strings.TrimSpace(string(stdout)), 10, 64)

	})

	return e.size
}
Mount BTRFS drive to WSL

Had to mount a BTRFS drive to windows recently, while winbtrfs does work for some basic operations, I wouldn't really trust it for funky things. In this case I had to consolidate multiple drives into a single one.

// windows
// get the drive ID
GET-CimInstance -query "SELECT * from Win32_DiskDrive"
// needs administrator—mount the drive
wsl --mount \\.\PHYSICALDRIVE1 --bare

// wsl | ubuntu
sudo apt install btrfs-progs
sudo mount /dev/sdd3 /mnt/$btrfs_mount
sudo btrfs device scan

// windows
wsl --unmount \\.\PHYSICALDRIVE1
Brotli recursive static compression

The brotli-cli lacks an -r flag for now, can be circumvented using the output of find and piping it into xargs.

find . -name "*.{file-extension}" -print0 | xargs -0 brotli -Z
Serving Raw Files over Caddy

Rewrite the Content-Type header to serve raw files, as raw file delivery behaves inconsistently across different browsers.

@pgp_file path_regexp ^.*/public_pgp$
header @pgp_file Content-Type "text/plain; charset=utf-8"

@raw_file path_regexp ./raw/*
header @raw_file Content-Type "text/plain; charset=utf-8"

@ico_file path_regexp ^.*ico$
header @ico_file Content-Type "image/x-icon"

@jpg_file path_regexp .*jpe?g$
header @jpg_file Content-Type "image/jpeg"

@png_file path_regexp ^.*png$
header @png_file Content-Type "image/png"

@webp_file path_regexp ^.*webp$
header @webp_file Content-Type "image/webp"
FFMPEG Integer Scaling

Had some old pixel art I had to upscale.

ffmpeg -i input.webm -vf "scale=4800:2700:flags=neighbor" -c:v libvpx-vp9 -an output.webm