Skip to content

Instantly share code, notes, and snippets.

View brettinternet's full-sized avatar
👋

Brett brettinternet

👋
View GitHub Profile
@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"
const createList = (length) =>
[...new Array(length)].map((_, index) => ({id: (index + 1).toString() }))
const length = 10000
const items = createList(length).map(c => ({ ...c, inner: createList(length) }))
console.log(items)
const lastId = length.toString()
const itemId = lastId
const innerItemId = lastId
@brettinternet
brettinternet / try-catch-helper.ts
Last active December 15, 2022 22:57
try catch hell 🤷‍♂️
const tc =
<T extends (...args: Parameters<T>) => ReturnType<T>>(
cb: T,
condition = true
): ((...args: Parameters<T>) => ReturnType<T> | undefined) =>
(...args: Parameters<T>) => {
if (condition) {
try {
return cb(...args)
} catch (error) {
@brettinternet
brettinternet / 0-remote-setup-arch.sh
Last active December 5, 2022 07:49
Arch Linux setup with dm-crypt encryption, btrfs and rEFInd
#!/bin/bash
# Work from a terminal you're more comfortable in (and for scrolling)
set -xe
if passwd -S root | grep -q "NP"; then
echo "Set root password:"
passwd
fi