Skip to content

Instantly share code, notes, and snippets.

View mstevenson's full-sized avatar

Michael Stevenson mstevenson

View GitHub Profile
mstevenson /
Last active November 25, 2022 00:47
Download all images from an Internet Archive collection and write the caption to a text file
import internetarchive as ia
from pathlib import Path
import argparse
import time
config = dict(general=dict(secure=False))
def download_collection(collection_name, output_dir):
search = ia.search_items(f'collection:{collection_name}', config=config)
dir = Path(output_dir) / collection_name
mstevenson /
Created November 14, 2022 21:11
Extract frames every n seconds from a directory of videos
# extract frames every n seconds from a directory of videos
import cv2
import os
from pathlib import Path
video_base_path = Path('videos')
frames_root_path = Path('frames')
interval = 30 #seconds
mstevenson /
Last active December 23, 2023 10:06
Manual image captioning tool for Stable Diffusion training
# Python GUI tool to manually caption images for machine learning.
# A sidecar file is created for each image with the same name and a .txt extension.
# [control/command + o] to open a folder of images.
# [page down] and [page up] to go to next and previous images. Hold shift to skip 10 images.
# [shift + home] and [shift + end] to go to first and last images.
# [shift + delete] to move the current image into a '_deleted' folder.
# [escape] to exit the app.
import os
mstevenson /
Created November 8, 2022 05:30
Stable Diffusion training image cropping utility
import os
from PIL import Image
path = 'input_image_dir_path'
save_path = 'output_image_dir_path'
for filename in os.listdir(path):
img = + filename)
if img is not None:
width, height = img.size
mstevenson / sd_crop.js
Created October 14, 2022 23:28
Photoshop script to crop and resize images for Stable Diffusion training
#target photoshop
// open a folder of images
var folder = Folder.selectDialog("Select a folder of JPGs to crop");
var files = folder.getFiles("*.jpg");
// create a folder to save the files to if it doesn't exist
var saveFolder = new Folder(folder + "/cropped");
if (!saveFolder.exists) saveFolder.create();
mstevenson /
Created August 10, 2022 15:37 — forked from dreness/
A somewhat brutal repair of Synalize It! Pro for macOS, which is broken by linking against the system-provided python which no longer exists.

check current python linkage

% otool -L /Applications/Synalyze\ It\!\\ It\!\ Pro | grep Python
	/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.16)

Download and install Python2.7.16 for macOS. By default this lands in /Library/Frameworks/Python.framework/Versions/2.7

Make a copy of the Synalize It! Pro app bundle, e.g. to your desktop.

cp -R /Applications/Synalyze\ It\!\ ~/Desktop
mstevenson /
Last active July 18, 2022 19:34
Shell script to batch convert old QuickTime moves to MP4
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [ ! -d "$OUTPUT" ]; then
mkdir -p "$OUTPUT";
for i in *.mov;
mstevenson / .gitattributes
Last active March 6, 2023 16:31
Git configuration files for Unity projects
*.cs diff=csharp
# Macro attribute, linguist-generated means the file is ignored for the
# repository's language statistics and diffs are hidden by default
[attr]unity-yaml-file -text -merge=unityamlmerge linguist-generated
# Macro attribute for LFS files
[attr]lfs-file filter=lfs diff=lfs merge=lfs -text
### Unity YAML Files ###
mstevenson / RequiredFieldAttribute.cs
Created November 8, 2019 05:33
Visually indicate that a Unity inspector value is required.
using System;
using UnityEngine;
/// <summary>
/// Indicates that an inspector field must have its value assigned during authoring.
/// </summary>
public class RequiredFieldAttribute : PropertyAttribute
mstevenson / PennerEasing.cs
Created December 30, 2018 16:49
Robert Penner's Easing Functions ported to Unity
* PennerEasing
* Calculates a float value between two target values using
* Robert Penner's easing equations for interpolation over a specified duration.
* @author Darren David
* @version 1.0
* Credit/Thanks:
* Robert Penner - The easing equations we all know and love