Skip to content

Instantly share code, notes, and snippets.

View brettinternet's full-sized avatar
👋

Brett brettinternet

👋
View GitHub Profile
@brettinternet
brettinternet / pi-frame.sh
Created April 24, 2024 22:41
frame image buffer for a simple console slide show with a Raspberry Pi (Zero W)
# 1. Setup raspbian lite - no desktop environment or Xorg necessary. Install `fbi`.
# 2. Sync files to Pi:
rsync -ahP --delete ./slides remote-ssh-host:~
# 3. Append to ~/.profile to run on startup
if [[ $(fgconsole 2>/dev/null) == 1 ]]; then
fbi -d /dev/fb0 -noverbose -a -t 60 -cachemem 0 $HOME/slides/*
@brettinternet
brettinternet / zfs-supported-kernel-version.sh
Created January 21, 2024 07:36
Get the major/minor versions of the linux kernel that are supported by ZFS
#!/bin/sh
curl -sS 'https://raw.githubusercontent.com/openzfs/zfs/master/META' | awk '$1 == "Linux-Maximum:" { print $2; exit }'
@brettinternet
brettinternet / Taskfile.yaml
Last active December 31, 2023 15:39
docker-compose example with SOPS secrets, multi-domain Traefik, Cloudflare DNS and Cloudflare tunnel
# install go-task
---
version: "3"
vars:
PROJECT: myproject
SECRETS_FILE: sops.env
COMPOSE_FILES:
sh: find . -type f -iname "compose*.yaml" -exec basename {} ';' | sort -r
COMPOSE_FILES_ARGS: -f {{ .COMPOSE_FILES | splitLines | join " -f " }}
@brettinternet
brettinternet / compose.yaml
Last active December 31, 2023 15:42
Local netdata utility at http://netdata.localhost:8080
version: "3"
name: utils
x-options: &options
environment: &environment
TZ: "${TIMEZONE}"
restart: unless-stopped
networks:
- utils
@brettinternet
brettinternet / oops-zfs.md
Last active December 10, 2023 02:35
Recovery from ZFS oops

The stages of ZFS grief

Disk passthrough to a VM managing my ZFS array.

$ qm set 100 -scsi1 /dev/disk/by-id/…
$ qm set 100 -scsi2 /dev/disk/by-id/…
$ …
defmodule MyApp.RepoConnectionReaper do
@moduledoc """
Disconnect all connections after a X minutes to reset cache build-up and leaky memory on long-lived connections
Especially useful for dynamic queries which contribute to this build-up.
Alternatively, use this Repo option e.g. `Repo.all(query, prepare: :unnamed)` to avoid using named prepared statements
on queries that are dynamic enough to not cache the prepared statement on the connection.
See also
- https://github.com/elixir-ecto/db_connection/issues/99
@brettinternet
brettinternet / map_dev_id.sh
Created December 6, 2023 03:22
Maps device letter to disk by ID
#!/bin/bash
find /dev/disk/by-id/ -type l | xargs -I{} ls -l {} | grep -v -E '[0-9]$' | sort -k11 | cut -d' ' -f9,10,11,12
@brettinternet
brettinternet / slack_cleaner.py
Created July 26, 2023 04:20
Delete your own messages in Slack channels
#!/usr/bin/python
from slack_cleaner2 import *
s = SlackCleaner('TOKEN')
channel = "CHANNEL_NAME"
for msg in s.c[channel].msgs(with_replies=True):
if msg.user == s.myself:
print(f"DELETED: {msg.text}")
@brettinternet
brettinternet / react-query-derive-maybe-user.tsx
Last active June 18, 2023 04:17
Derive data result from nullable with data selection - useful when you use react query as a state tool
// Nullable user example:
type MaybeUser = UserQuery['user']
/**
* Possibly null user, such as on an auth page
* Here's a description on why these overloads are required: https://stackoverflow.com/a/67640634
*/
export function useMaybeUser<UserData = MaybeUser>(
select: (user: MaybeUser) => UserData
@brettinternet
brettinternet / update-git-mirrors.mjs
Last active April 23, 2023 03:50
Update list of git mirrors
/**
* environment variables:
* WORKING_DIRECTORY - set to absolute path such as /tmp
* GIT_REMOTE_{some unique number or key} - set to cloneable HTTPS repo URL such as 'https://github.com/brettinternet/homelab'
*/
import { stat } from "node:fs/promises"
import { existsSync } from "node:fs"
import { dirname, parse as pathParse, join as pathJoin } from "node:path"
import { parse as urlParse, fileURLToPath } from "node:url"
import { promisify } from "node:util"