Skip to content

Instantly share code, notes, and snippets.

View shanecelis's full-sized avatar

Shane Celis shanecelis

View GitHub Profile
@shanecelis
shanecelis / record-window
Created December 31, 2024 05:02
Record a window excluding title bar of a macOS application
#!/bin/bash
# record-window
function usage() {
echo "usage: record-window [-hf] [-n window-number] <application> <capture.mov>" >&2;
echo " -h help; show usage (this)" >&2;
echo " -f force recording (remove previous output file if present)" >&2;
echo "Record a window excluding title bar of an application (case-sensitive)" >&2;
}
# b-graph.dot
#
# $ dot -Tpng b-graph.dot -o b-graph.png
digraph G {
Foo0 [shape=record, label="{Foo | Children | Observers}"];
Bar0 [shape=record, label="{Bar | OhHiMark}"];
Bar1 [shape=record, label="{Bar | Children}"];
Baz0 [shape=record, label="{Baz}"];
Observer0 [shape=record, label="{system}"];
Foo0 -> Bar0[label="child"];
@shanecelis
shanecelis / click.rs
Created July 20, 2024 10:22
Click event for bevy
/* Original code Copyright (c) 2024 Shane Celis[1]
Licensed under the MIT License[2] or Apache License v2.0[3]
[1]: https://mastodon.gamedev.place/@shanecelis
[2]: https://opensource.org/licenses/MIT
[3]: https://www.apache.org/licenses/LICENSE-2.0
*/
//! Click event for Bevy.
//!
@shanecelis
shanecelis / try_collect.rs
Created March 23, 2024 04:56
Try to collect from an iterator that may fail.
use std::fmt::Debug;
use std::iter::FromIterator;
/// Try to collect from an iterator that may fail.
///
/// # Motivation
///
/// I really wanted to be able to turn a `Iterator<Item = u8>` into a String
/// more easily.
///
#!/bin/bash -e
# unity-log
usage() {
echo "Usage: unity-log [-te] <Company> <Application>" >&2;
echo " -t tail log" >&2;
echo " -e editor log" >&2;
exit 2;
}
cmd=echo;
@shanecelis
shanecelis / befungoban.js
Created December 21, 2022 10:10
A Befunge + Sokoban mashup for sprig
/*
@title: Befungoban
@author: Shane Celis @shanecelis
https://esolangs.org/wiki/Befunge
http://qiao.github.io/javascript-playground/visual-befunge93-interpreter/
*/
const player = "p";
const selection = "b";
@shanecelis
shanecelis / DragManipulator.cs
Last active December 11, 2024 20:41
This manipulator makes a visual element draggable at runtime in Unity's UIToolkit.
/* Original code[1] Copyright (c) 2022 Shane Celis[2]
Licensed under the MIT License[3]
[1]: https://gist.github.com/shanecelis/b6fb3fe8ed5356be1a3aeeb9e7d2c145
[2]: https://twitter.com/shanecelis
[3]: https://opensource.org/licenses/MIT
*/
using UnityEngine;
using UnityEngine.UIElements;
@shanecelis
shanecelis / ChildAnnotator.cs
Last active October 30, 2024 20:14
Fake CSS pseudo classes :first-child and :last-child in Unity's UIToolkit with regular USS classes .first-child and .last-child.
/* Original code[1] Copyright (c) 2022 Shane Celis[1]
Licensed under the MIT License[1]
[1]: https://gist.github.com/shanecelis/1ab175c46313da401138ccacceeb0c90
[1]: https://twitter.com/shanecelis
[1]: https://opensource.org/licenses/MIT
*/
using UnityEngine.Scripting;
using UnityEngine.UIElements;
@shanecelis
shanecelis / ProgressBar.cs
Last active August 31, 2022 05:43
Exposes runtime progress bar for UIToolkit for Unity 2020.3.
/** Using UIElements and want to use UIToolkit's progress bar at runtime? Hope,
you're using Unity 2021.1 or later. If you aren't, you can expose the
progress bar in Unity 2020.3 and perhaps even earlier versions (not tested).
`com.unity.ui v1.0.0-preview.18` uses the following #ifdef for the
`ProgressBar` class[1]:
```
#if !UIE_PACKAGE || UNITY_2021_1_OR_NEWER
```
@shanecelis
shanecelis / MyEnumerable.cs
Created May 10, 2022 02:40
Demonstration of how to make an allocation-less struct IEnumerator.
/** Suppose you want to do a `foreach` on your collection without any
allocations. You know it's possible.
You've heard you need to use a struct IEnumerator, but how?
*/
using System.Collections;
using System.Collections.Generic;
/** You implement IEnumerable<T> in your collection class. */
public class MyEnumerable<T> : IEnumerable<T> {