Skip to content

Instantly share code, notes, and snippets.

View pirate's full-sized avatar

Nick Sweeting pirate

View GitHub Profile
@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
@pirate
pirate / accellerated_django_paginator.py
Created September 12, 2024 03:59
A faster version of the default Django Paginator
# This is an improved Django Paginator that makes Admin list view pages load much faster.
# You can tell if you need this if you see a big slow COUNT() query
# in the django_debug_toolbar SQL panel on every admin list view.
# It improves performance by avoiding running a potentially costly DISTINCT query to
# count total rows on every pageload. Instead, when possible (when there are no filters)
# it does a significantly simpler SELECT COUNT(*) tablename to get the total.
from django.core.paginator import Paginator
@pirate
pirate / udm_fancontrol_setup.sh
Created June 4, 2024 10:34
Setup Unifi Dream Machine (UDM, UDM-SE, etc.) automatic fan speeds control to lower temps and increase hard drive lifespan.
#!/bin/bash
# Installs and configures fancontrol to automatically run Unifi Dream Machine (UDM) fans harder & lower temperatures.
#
# Context: Unifi equipment typically runs *very* hot from the factory unless you customize it.
# I don't want my hard drives to run as hot as they let them get by default (55ºC+), because it shortens lifespan (ideal temp is ~35-45C).
#
# Further Reading:
# - https://linux.die.net/man/8/fancontrol
# - https://community.ui.com/questions/Unifi-Dream-Router-fan-speed/1cb9cf18-e8a0-44b4-8402-ee9bac367bc0
# - https://www.reddit.com/r/Ubiquiti/comments/13imgqj/udm_pro_fan_speed_is_this_normal/
@pirate
pirate / pydantic_config.py
Last active April 19, 2026 17:38
Pydantic config loader and dumper with dynamic defaults based on previous values and support for TOML, INI, JSON, Env, and ArchiveBox schema formats.
import re
import os
import sys
import toml
import json
import orjson
import platform
import inspect
import tomllib
import ini2toml