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 / iterated_prisoners_dillema.html
Created February 7, 2025 14:07
Mini JS web game allowing you to simulate iterated prisoners dillema rounds against a bot character with a few different strategies
<!-- Iterated prisoners dillema mini JS web game by Nick Sweeting on 2025-02-07 https://blog.sweeting.me -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Iterated Prisoner's Dilemma Game</title>
<style>
/* Basic Styles */
body {
font-family: sans-serif;
@pirate
pirate / dxp4800_plus_lspci_fio_tests.txt
Last active January 30, 2025 22:50
lspci and fio speed testing the internal and main nvme slot speeds on a UGREEN DXP4800 Plus NAS
# This is the output of testing the nvme slot speeds on a UGREEN DXP4800 Plus NAS
# The internal slot is limited to PCIe 3.0 speeds and 25w compared to the main slots at PCIe 4.0 speeds and 75w.
# https://www.reddit.com/r/homelab/comments/1bya4n1/ugreen_nas_ama/m9sqojt/
root@ugnas[~]# fio --filename=/dev/nvme2n1 --direct=1 --rw=read --bs=1M --ioengine=libaio --iodepth=32 --numjobs=1 --name=seq_read_test --size=10g
seq_read_test: (g=0): rw=read, bs=(R) 1024KiB-1024KiB, (W) 1024KiB-1024KiB, (T) 1024KiB-1024KiB, ioengine=libaio, iodepth=32
fio-3.33
Starting 1 process
Jobs: 1 (f=1): [R(1)][-.-%][r=3360MiB/s][r=3360 IOPS][eta 00m:00s]
seq_read_test: (groupid=0, jobs=1): err= 0: pid=5961: Thu Jan 30 14:39:40 2025
@pirate
pirate / truenas_enable_boot_write.sh
Last active January 29, 2025 00:49
Commands to enable read-write / apt install on the boot pool for TrueNAS scale
# enable read-write / apt install on the boot pool for TrueNAS scale
mount -o remount,rw 'boot-pool/ROOT/24.10.2/usr'
chmod +x /bin/apt*
chmod +x /usr/bin/dpkg
apt-get update
/usr/local/libexec/disable-rootfs-protection
@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 25, 2025 15:11
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)