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 / 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 May 15, 2024 12:40
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
@pirate
pirate / ini_to_toml.py
Created May 15, 2024 12:39
Convert an INI config string into a TOML config string with Python
from typing import Dict, Any, List
import configparser
import json
import ast
JSONValue = str | bool | int | None | List['JSONValue']
def load_ini_value(val: str) -> JSONValue:
"""Convert lax INI values into strict TOML-compliant (JSON) values"""
@pirate
pirate / add_debug_entitlement.sh
Created March 28, 2024 09:02 — forked from talaviram/add_debug_entitlement.sh
Simple Utility Script for allowing debug of hardened macOS apps.
#! /bin/bash
# Simple Utility Script for allowing debug of hardened macOS apps.
# This is useful mostly for plug-in developer that would like keep developing without turning SIP off.
# Credit for idea goes to (McMartin): https://forum.juce.com/t/apple-gatekeeper-notarised-distributables/29952/57?u=ttg
# Update 2022-03-10: Based on Fabian's feedback, add capability to inject DYLD for sanitizers.
#
# Please note:
# - Modern Logic (on M1s) uses `AUHostingService` which resides within the system thus not patchable and REQUIRES to turn-off SIP.
# - Some hosts uses separate plug-in scanning or sandboxing.
# if that's the case, it's required to patch those (if needed) and attach debugger to them instead.