Skip to content

Instantly share code, notes, and snippets.

View mstevenson's full-sized avatar

Michael Stevenson mstevenson

View GitHub Profile
@mstevenson
mstevenson / lfs.gitattributes
Last active September 27, 2023 00:57
Git LFS attributes file for Unity, Maya and ZBrush
# unity
*.unitypackage filter=lfs diff=lfs merge=lfs -text
*.cubemap filter=lfs diff=lfs merge=lfs -text
*.spm filter=lfs diff=lfs merge=lfs -text
# models
*.mb filter=lfs diff=lfs merge=lfs -text
*.MB filter=lfs diff=lfs merge=lfs -text
@mstevenson
mstevenson / FileUtility.cs
Created December 27, 2012 08:52
A small file utility class for Unity. Transform an absolute path into an Assets folder relative path, and get a list of all Resources directories in the project.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class FileUtility {
/// <summary>
/// Determine whether a given path is a directory.
/// </summary>
@mstevenson
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
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 darren-code@lookorfeel.com
* @version 1.0
*
* Credit/Thanks:
* Robert Penner - The easing equations we all know and love
@mstevenson
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>
[AttributeUsage(AttributeTargets.Field)]
public class RequiredFieldAttribute : PropertyAttribute
{
}
@mstevenson
mstevenson / ia_image_downloader.py
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
mstevenson / CreateAssetFromScript.cs
Created February 6, 2013 22:39
Creates an on-disk instance of a Unity ScriptableObject. To install, copy CreateAssetFromScript.cs into an Editor folder in your Unity project. To use, first select a script that inherits from ScriptableObject in the Project window, then select the menu Assets > Create Asset From ScriptableObject.
using UnityEngine;
using UnityEditor;
using System;
public class CreateAssetFromScript : Editor {
[MenuItem("Assets/Create Asset From Manager Script", false, 10000)]
public static void CreateManager ()
{
ScriptableObject asset = ScriptableObject.CreateInstance (Selection.activeObject.name);
@mstevenson
mstevenson / sd_crop.py
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 = Image.open(path + filename)
if img is not None:
width, height = img.size
@mstevenson
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
mstevenson / fix-synalize-it.md
Created August 10, 2022 15:37 — forked from dreness/fix-synalize-it.md
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\!\ Pro.app/Contents/MacOS/Synalyze\ 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\!\ Pro.app ~/Desktop