Skip to content

Instantly share code, notes, and snippets.

@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 / 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
@greg-randall
greg-randall / remove.js
Last active February 26, 2025 19:22
Remove invisible elements from html -- helps with web scraping by identifying and removing invisible elements from a webpage's DOM to focus on content visible to website users.
/**
* Determines if a DOM element is visible to the user
*
* Checks multiple CSS properties that can hide elements:
* - display: none
* - visibility: hidden
* - opacity: 0
* - zero dimensions (width and height)
* - parent visibility (propagated via data attribute)
*
@greg-randall
greg-randall / norm.py
Created February 19, 2025 00:52
This tool normalizes the loudness of MP3 audio files to a consistent level.
"""
This tool normalizes the loudness of MP3 audio files to a consistent level. Here's how to use it:
Run the script with a directory path: python script.py /path/to/mp3s
By default, it sets audio to -14 LUFS (loudness units) and prevents clipping at -0.1dB
It creates new files prefixed with "processed_" unless you use --overwrite
You can customize the target loudness with --target-lufs and peak limit with --threshold-db
The tool analyzes each MP3 file, adjusts its volume to the target loudness, applies a limiter to prevent distortion, and saves the processed version.
"""
@greg-randall
greg-randall / index.php
Created February 19, 2025 00:49
Recording Comparison. Reads a list of recordings in from a text file 'voices.csv', the first column is the voice name, and the second is a description. The recordings go in the same folder and the filename is generated by adding ".mp3" to the voice name.
<!DOCTYPE html>
<html>
<head>
<title>TTS Voice Comparison</title>
<style>
body {
margin: 0;
padding: 20px;
padding-bottom: 120px;
}
@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 / codec-reader.py
Last active October 29, 2024 05:49 — forked from Steve-Tech/codec-reader.py
Codec Reader for HTML Video Tags, gets the correct codecs parameter for AV1, HEVC (H.265), and H.264 videos.
import json
import mimetypes
import subprocess
import sys
# Codec Reader for HTML Video Tags by Steve-Tech
# Usage: python3 codec-reader.py [-d] file_name
# Requires ffmpeg and ffprobe to be installed.
#
# Supported Codecs:
@greg-randall
greg-randall / role-limiter.php
Created June 12, 2024 18:50
WordPress plugin to limit editing of pages and their children to certain user roles.
<?php
/**
* Plugin Name: Role-Based Page Editor Limitations
* Description: This plugin restricts editing capabilities of specific pages to certain user roles. It dynamically creates roles if they don't exist and assigns them editor capabilities. It then checks if a user with a specific role is trying to edit a page that they're not assigned to, and if so, it removes their editing capabilities for that page. Edit the $role_page_map array to specify which roles can edit which pages.
* Version: 1
* Author: Greg R.
*/
/* For example you want to make it so that some peolple at your company can edit /subpage/ and all the children under that page, so you can create a user role that restricts them to jus that section of the site. */