Skip to content

Instantly share code, notes, and snippets.

@capnslipp
capnslipp / NonDrawingGraphic.cs
Last active February 12, 2024 20:44
A UnityEngine.UI.Graphic subclass that provides only raycast targeting, skipping all drawing.
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @purpose: A UnityEngine.UI.Graphic subclass that provides only raycast targeting, skipping all drawing.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Add a `NonDrawingGraphic` component to the GameObject you want clickable, but without its own image/graphics.
/// @intended project path: Assets/Plugins/UnityEngine UI Extensions/NonDrawingGraphic.cs
/// @interwebsouce: https://gist.github.com/capnslipp/349c18283f2fea316369
using UnityEngine;
using UnityEngine.UI;
@capnslipp
capnslipp / TestLateFixedUpdate.cs
Created May 18, 2014 01:19
Unity LateFixedUpdate pattern test script
using UnityEngine;
using System.Collections;
public class TestLateFixedUpdate : MonoBehaviour
{
void OnEnable() {
StartCoroutine("RunLateFixedUpdate");
}
@capnslipp
capnslipp / git-lf
Last active June 28, 2023 19:37
Lost & Found for Git: tag all dangling commits, for those wonderful “oh shit” moments (and cleanup those tags after recovered the lost path)
#!/usr/bin/env bash
# Tags all dangling commits in a Git repo (for the wonderful “oh shit” moments).
# @from: https://gist.github.com/capnslipp/2656868
git fsck --lost-found #--no-reflogs --full --root --cache --tags --unreachable
find '.git/lost-found/commit' -type f | while read i; do
commit_sha=`cat "$i"`
git tag -f "git-lf/commit/$commit_sha" $commit_sha
done
@capnslipp
capnslipp / GameObjectFindComponentExtension.cs
Last active June 20, 2023 13:06
Unity3D MonoBehaviourPopulateExtension & friends
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @purpose: More-flexible GO-tree searching for Components by type, configurable via `SearchExtent` enum arg.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Call `this.gameObject.FindComponent<«component-type»>(«SearchExtent-type»);`.
/// @intended project path: Assets/Plugins/UnityEngine Extensions/GameObjectFindComponentExtension.cs
/// @interwebsouce: https://gist.github.com/capnslipp/ac26e38fce770b5c4594
using System;
using UnityEngine;
@capnslipp
capnslipp / DisableWhenAttribute.cs
Last active June 18, 2023 19:47
ShowWhen, HideWhen, EnableWhen, & DisableWhen Attributes for #Unity3D
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @purpose: Shows a field as disabled in Unity's Inspector only when a different method/property/field in the same MonoBehaviour returns/is-equal-to a given value or values.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Add `[DisableWhen(typeof(«MonoBehaviour-sub-type-name»), "«trigger-member-name»", «value-that-the-trigger-member-returns»)]` attribute to a (serializable public) field on your `MonoBehaviour`-class.
/// @intended project path: Assets/Plugins/EditorUtils/DisableWhenAttribute.cs
/// @interwebsouce: https://gist.github.com/capnslipp/9b99f83aa7b80dfb589a5b23e8e0cfa0
using System;
using UnityEngine;
@capnslipp
capnslipp / SerializedPropertyValueExtension.cs
Last active June 18, 2023 19:45
Genericized #Unity3D SerializedProperty value access, an extension that should be part of the API.
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @purpose: Genericized Unity3D SerializedProperty value access.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Use as you would a native SerializedProperty method;
/// e.g. `Debug.Log(mySerializedProperty.Value<Color>());`
/// @intended project path: Assets/Plugins/Editor/UnityEditor Extensions/SerializedPropertyValueExtension.cs
/// @interwebsouce: https://gist.github.com/capnslipp/8516384
using System;
@capnslipp
capnslipp / .gitconfig
Last active January 31, 2023 16:17
my global .gitconfig file(s), with tweaks for: command verbosity, more-distinct colors, and handy aliases
# Base
[core]
excludesfile = /Users/capnslipp/.git_excludes
attributesfile = /Users/capnslipp/.git_attributes
#editor = mate -w
editor = macdown-wait
whitespace = tabwidth=4, space-before-tab, indent-with-non-tab, blank-at-eol, blank-at-eof
# defaults: whitespace = blank-at-eol, space-before-tab, -indent-with-non-tab, -tab-in-indent, blank-at-eof, trailing-space, -cr-at-eol, tabwidth=8
quotepath = false
@capnslipp
capnslipp / git-list-dupe-commits
Last active January 12, 2023 23:27
A small, inefficient, naïvely-written bash script to list all duplicate commits (those with the same patch-id) in a git repo.
#!/usr/bin/env bash
test ! -z "$1" && TARGET_COMMIT_SHA="$1" || TARGET_COMMIT_SHA="HEAD"
TARGET_COMMIT_PATCHID=$(
git show --patch-with-raw "$TARGET_COMMIT_SHA" |
git patch-id |
cut -d' ' -f1
)
MATCHING_COMMIT_SHAS=$(
@capnslipp
capnslipp / swift-build-driverkit
Last active December 29, 2022 17:58
Per-platform `swift-build-…` scripts
#!/usr/bin/env bash
arch="$(uname -m)"
sdk_path="$(xcrun --sdk driverkit --show-sdk-path)"
sdk_version="$(xcrun --sdk driverkit --show-sdk-version)"
echo "Running: " \
swift build -Xswiftc "-sdk" -Xswiftc "${sdk_path}" -Xswiftc "-target" -Xswiftc "${arch}-apple-driverkit${sdk_version}" "$@"
swift build -Xswiftc "-sdk" -Xswiftc "${sdk_path}" -Xswiftc "-target" -Xswiftc "${arch}-apple-driverkit${sdk_version}" "$@"
@capnslipp
capnslipp / When Song Finishes, Pause.applescript
Last active December 29, 2022 17:30
Pause Spotify after the current song finishes playing
(*
@author: Slipp Douglas Thompson
@purpose: Pauses Spotify after the current song finishes playing.
@todo: Optimize so it's more efficient.
@usage: Drop a compiled script (a .scpt file, converted with AppleScript Editor if this is a .applescript file) into ~/Library/Scripts/Applications/Spotify.
Ensure than “Show Script menu in menu bar” is enabled (which can be found in the AppleScript Editor preferences).
When playing a song in Spotify and wishing to stop the music when the track finished, choose “When Song Finishes, Pause” from the script menu, and then walk, walk away.
*)
tell application "Spotify"
log "“When Song Finishes, Pause”: player state is " & (player state)