Skip to content

Instantly share code, notes, and snippets.

@greg-randall
greg-randall / detect_faces_overlay.py
Created June 8, 2026 15:00
detect_faces_overlay.py
#!/usr/bin/env python3
"""Run all four face detectors and produce a single overlay image per input.
Each model's bounding box is drawn in a distinct colour at 50% transparency,
and a legend is rendered at the bottom of the image.
Output: ``{stem}_overlay{ext}``
"""
import sys
@greg-randall
greg-randall / detect_faces_compare.py
Created June 8, 2026 14:59
detect_faces_compare.py
#!/usr/bin/env python3
"""Run four face detectors (MediaPipe, RetinaFace, SCRFD/InsightFace, YOLOv11-face)
on all images in the current folder and save comparison outputs.
Output naming: ``{stem}_{modelname}{ext}`` — one file per model per input.
"""
import sys
import urllib.request
from pathlib import Path
@greg-randall
greg-randall / normalize.py
Created March 25, 2026 14:06
Normalizes a folder of audio files to the same volume
import os
from pydub import AudioSegment
from pathlib import Path
import pyloudnorm as pyln
import soundfile as sf
import numpy as np
def process_audio(input_path, target_lufs=-14, threshold_db=-0.1, overwrite=False):
"""
Process audio file by:
import json
import requests
import base64
import wave
import io
url = 'https://inworld.ai/api/create-speech'
headers = {
'accept': '*/*',
@greg-randall
greg-randall / gen-audio.py
Created July 13, 2025 14:21
This Python script converts a large text file into a series of audio files. You can run it from the command line by passing in your text file and choosing a voice with the --voice flag (e.g., --voice bm_lewis or the default --voice bf_emma).
"""
A script to convert a large text file into multiple speech audio files
by splitting the text into chunks and processing them sequentially.
"""
import argparse
import datetime
import re
import warnings
from pathlib import Path
@greg-randall
greg-randall / get-genres.py
Last active July 7, 2025 19:58
Python script that gets book genres from Goodreads for a list of book IDs and saves them to a JSONL file.
import asyncio
import argparse
import json
import sys
from pathlib import Path
from typing import List, Tuple, Set
from bs4 import BeautifulSoup
from curl_cffi.requests import AsyncSession
from pathvalidate import sanitize_filename
@greg-randall
greg-randall / index.php
Last active July 1, 2025 14:23
HTML Cleaner. Paste dirty html into a field, and it removes nearly all HTML attributes (except the ones you want -- src, href, alt, and a couple others), and formats. Using proper DOMDocument PHP parser.
<?php
/*
Note that the cleaner sends the html to DirtyMarkup for formatting.
Example input:
<div class=WordSection1>
<p class=MsoNormal align=center style='text-align:center'><span
style='font-size:16.0pt;line-height:107%;font-family:"Abadi Extra Light",sans-serif'>Test
Clean<o:p></o:p></span></p>
@greg-randall
greg-randall / name_cleaner.py
Last active June 3, 2025 20:28
Name similarity comparator. I use it to try and align data in spreadsheets. Run: python3 nametest.py sample_names.txt Then use the sample_names.csv to match in your spreadsheets.
"""
Name Matching Algorithm with Nickname and Typo Tolerance
# Basic usage with default thresholds:
python3 nametest.py sample_names.txt
# With custom thresholds:
python3 nametest.py sample_names.txt --first-threshold 80 --last-threshold 90 --last-distance 2 --first-distance 1
# With custom output file:
python3 nametest.py sample_names.txt --output-file my_matches.csv
@greg-randall
greg-randall / combine.sh
Created March 9, 2025 00:43
A Python utility that combines vertical image strips into a seamlessish panorama with smooth blending between overlapping regions.
"""
# Panorama Strip Combiner
A Python utility that combines vertical image strips into a seamless panorama with smooth blending between overlapping regions.
## What It Does
This script takes a directory of vertical image strips and combines them into a single panoramic image. It features:
- Automatic ordering of strips based on filename
@greg-randall
greg-randall / stripe.sh
Created March 9, 2025 00:38
This script processes a sequence of TIF images by cropping each image to a vertical strip from the center for use in slitscan image creation
#!/bin/bash
# This script processes a sequence of TIF images by cropping each image to a vertical strip from the center. Here's a breakdown:
# 1. It takes images from an input directory ("frames-try1") and saves the cropped versions to an output directory ("frames-03-trial").
# 2. The script extracts a vertical strip with a width of 105 pixels, centered in each image.
# 3. It uses ffprobe to determine the dimensions of the first image, calculates the center, and then uses ffmpeg to crop all images in the sequence.
# If you want to use this script, you might need to edit:
# - `INPUT_DIR` and `OUTPUT_DIR` paths to match your folder names