Gists

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.

 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
// Size returns the size of thr 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
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"
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
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