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 / 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.
const fs = require('fs');
const path = require('path');
const pathTo2captchaExtension = path.join(__dirname, '2captcha-solver');
const pathToPuppeteerStreamExtension = path.join(__dirname, 'puppeteer-stream-ext');
const { Cluster } = require('puppeteer-cluster');
const puppeteer = require("puppeteer-extra");
// add recaptcha plugin to solve captchas automatically
@pirate
pirate / docker_netcat_tunnel.sh
Last active January 29, 2024 08:07
Remote control a Docker container from another container in the same network using netcat, ssh, or pure python
# Three ways to control a docker container remotely from another docker container or host: Python, SSH, or ncat/nc/socat.
#
# Useful if you have two containers in a Docker Compose project and you want
# container1 to be able to run commands in container2 without having to share /var/run/docker.sock
#
# Further Reading: https://www.revshells.com/#bind
### 1. Using pure Python, the cleanest option
# supports dbus/x11/etc as it doesnt spawn a new login shell, correctly handles exiting after finished commands without hacky workarounds
@pirate
pirate / music_in_screenshots.py
Created January 12, 2024 14:43
Automatically detect song/video title/artist/album/metadata captured in screenshots using GPT-4-vision via the OpenAI API.
#!/usr/bin/env python3
# Script to extract song/video title, artist, album, etc. metadata from screenshots w/ GPT-4.
### Example Usage: ###############################################################################
#
# ➜ ~/Desktop # python3 music_in_screnshots.py --prompt=prompt.txt --attach=spotify_screenshot.PNG
# {
# "found_prominent_media": true,
# "all_strings": [
@pirate
pirate / imgur_backup.sh
Created May 4, 2023 05:26
Backup all Imgur URLs found in a given set of files using ripgrep + wget. Searches all text and binary files for any imgur URLs and downloads them locally.
#!/usr/bin/env bash
# imgur_backup.sh
# Backup all Imgur URLs found in a given directory using ripgrep + wget. Searches all text files, binary files, PDFs, database dumps, etc. for any imgur URLs and downloads them into a local directory.
#
# Note: make sure you apt/brew install ripgrep first, and replace grep with ggrep (brew install grep) on macOS
# Usage:
#
# $ mkdir db_dumps
# $ docker-compose exec postgres env PGPASSWORD=somepassword pg_dump -U someuser somedb > ./db_dumps/db_dump.sql
# $ bash imgur_backup.sh db_dumps
@pirate
pirate / monkey_patch_python_traceback.py
Last active January 24, 2024 23:23
Monkey patch the Python traceback system to modify function names, line numbers, file locations, etc.
# This code is a verbatim excerpt from the Jinja2 library that I'm preserving in a Gist for posterity
# https://github.com/pallets/jinja/blob/5b498453b5898257b2287f14ef6c363799f1405a/jinja2/debug.py
# -*- coding: utf-8 -*-
"""
jinja2.debug
~~~~~~~~~~~~
Implements the debug interface for Jinja. This module does some pretty
ugly stuff with the Python traceback system in order to achieve tracebacks
@pirate
pirate / pluginization_example.py
Last active December 18, 2023 10:18
Example of how to pluginize a complex app using a hooks system
"""
Example of a pluginized architecture breaking up a large app
with complex behavior (ArchiveBox), into a series of steps
that plugins can hook into.
(read from the bottom to top to get a quick overview)
"""
import re
import json
@pirate
pirate / asymptotic_progress_bar.py
Last active May 31, 2023 08:43
Animated CLI progress bar that fills up over N seconds, gracefully handling delays by filling slower and slower if the task exceeds the expected time. Good for when you don't know how long a task is going to take, but you still need it to A. feel fast in the avg case, and B. not freeze in the worst case (unknown total time).
#!/usr/bin/env python3
# asymptotic_progress_bar.py
# MIT License © 2021
#
# A pretty non-blocking python progress bar timer that fills up asymptotically until you stop it.
# Good for when you don't know how long a task is going to take (up to some max timeout),
# but you want it to feel fast and accurate / not stuck the whole time.
# ████████████████████ 0.9% (1/60sec)
# useful for animating e.g. file copy progress, download progress, package install progress, etc.
#