Skip to content

Instantly share code, notes, and snippets.

View pirate's full-sized avatar
🗃️
Archiving all the things!

Nick Sweeting pirate

🗃️
Archiving all the things!
View GitHub Profile
@pirate
pirate / Install FreeNAS SCALE on a partition and create a mirror.md
Created January 18, 2025 09:05 — forked from gangefors/Install FreeNAS SCALE on a partition and create a mirror.md
How to install TrueNAS SCALE on a partition instead of the full disk

Install TrueNAS SCALE on a partition instead of the full disk

The TrueNAS installer doesn't have a way to use anything less than the full device. This is usually a waste of resources when installing to a modern NVMe which is usually several hundred of GB. TrueNAS SCALE will use only a few GB for its system files so installing to a 16GB partition would be helpful.

The easiest way to solve this is to modify the installer script before starting the installation process.

@pirate
pirate / uuid7.py
Last active January 10, 2025 06:49
Pure python all-in-one UUIDv7 Implementation with graceful degradation between ms, µs, and ns timestamp precision
#!/usr/bin/env python3
# A single-file pure-python implementation of UUIDv7: (e.g. 01941230-851a-77fd-9b0b-8c8eac3b2d23)
# - makes sure UUIDv7s are always generated in alphabetic order (using system time + nanoseconds + extra monotonic random bits)
# - store millisecond, microsecond, nanosecond / variable precision timestamps all using same format
# - graceful degradation in precision, falls back to monotonic urandom bytes depending on user-provided timestamp precision
# - fully compatible with standard UUIDv7 spec (48 bit millisecond unix epoch time with rand_a & rand_b monotonic randomness)
# - allows you to generate a UUIDv7 with a given timestamp (of any precision), and parse the timestamp back out from any UUIDv7
# - helps guarantee that UUIDv7s generated back-to-back in the same thread are always monotonically sortable
# - helps lower the risk of UUIDv7s colliding with other UUIDv7s generated in other threads / on other machines
@pirate
pirate / cat_chat.tsx
Created December 24, 2024 09:11
A very simple dumb v0 app that lets you chat with your cat (listens for cat meows using browser microphone and then lets you type meows back).
'use client'
import { useState, useEffect, useRef } from 'react'
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
type Message = {
sender: 'human' | 'cat'
content: string
@pirate
pirate / scar_tissue.md
Created November 21, 2024 07:24 — forked from gtallen1187/scar_tissue.md
talk given by John Ousterhout about sustaining relationships

"Scar Tissues Make Relationships Wear Out"

04/26/2103. From a lecture by Professor John Ousterhout at Stanford, class CS142.

This is my most touchy-feely thought for the weekend. Here’s the basic idea: It’s really hard to build relationships that last for a long time. If you haven’t discovered this, you will discover this sooner or later. And it's hard both for personal relationships and for business relationships. And to me, it's pretty amazing that two people can stay married for 25 years without killing each other.

[Laughter]

> But honestly, most professional relationships don't last anywhere near that long. The best bands always seem to break up after 2 or 3 years. And business partnerships fall apart, and there's all these problems in these relationships that just don't last. So, why is that? Well, in my view, it’s relationships don't fail because there some single catastrophic event to destroy them, although often there is a single catastrophic event around the the end of the relation

@pirate
pirate / three_way_eventbus.js
Last active November 7, 2024 10:38
Implements an EventEmiter interface thats broadcasts all events across puppeteer context, page context, and service worker contexts.
/*
Moved to: https://github.com/ArchiveBox/abx-spec-behaviors
@pirate
pirate / puppeteer-larger-than-16384px.ts
Created October 3, 2024 14:47 — forked from matsuyama-k1/puppeteer-larger-than-16384px.ts
one solution for taking screen shot larger than 16384px with puppeteer. https://github.com/puppeteer/puppeteer/issues/359
import { Page } from "puppeteer";
import sharp from "sharp";
// Max texture size of the software GL backand of chronium. (16384px or 4096px)
// https://issues.chromium.org/issues/41347676
export const MAX_SIZE_PX = 16384;
const takeFullPageScreenshot = async (page: Page) => {
const pageHeight = await getPageHeight(page);
const deviceScaleFactor = page.viewport()?.deviceScaleFactor ?? 1;
@pirate
pirate / pluggy_registration_tests.py
Last active October 1, 2024 20:52
Exhaustive test for a patch to Pluggy to fix errors when attempting to register certain special object types.
#!/usr/bin/env python3
# Exhaustive test case demonstrating a patch to Pluggy's PluginManager.
# https://github.com/pytest-dev/pluggy/pull/536
# Fixes registration of pluggy namespaces that are modules/classes/instances with special attrs:
# - @property
# - @computed_field
# - @classproperty
# - @classmethod
# - @staticmethod
# - Meta classes (e.g. django models)
@pirate
pirate / pydantic_settings_with_defaults.py
Last active September 23, 2024 00:11
pydantic_settings BaseSettings model that allows using functions as that depend on other fields as default values
#!/usr/bin/env python
from typing import Callable
from pydantic import model_validator, TypeAdapter
from pydantic_settings import BaseSettings, SettingsConfigDict
class ModelWithDefaults(BaseSettings):
"""
This is an addon to pydantic_settings's BaseSettings that allows you to use
@pirate
pirate / create_random_uid_user.yml
Created September 22, 2024 23:21
Ansible playbook to create a new user with a random available uid & gid
- name: Determine available groups
getent:
database: group
- name: Add additional groups to user
user: name="{{user}}" groups="{{item}}" append=yes
when: item in ansible_facts.getent_group
with_items:
- sudo
- wheel
@pirate
pirate / mapmyride_downloader.sh
Created September 19, 2024 08:30
Download all your MapMyRide / MapMyFitness workout TCX files using your account data export CSV
#!/usr/bin/env bash
### Bash Environment Setup
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
# set -o xtrace
# set -x
# shopt -s nullglob
set -o errexit
set -o errtrace