Skip to content

Instantly share code, notes, and snippets.

Avatar

Shane Celis shanecelis

View GitHub Profile
@shanecelis
shanecelis / RawButton.cs
Created Nov 21, 2021
A style-less Button for Unity's UIToolkit.
View RawButton.cs
using System;
using UnityEngine.Scripting;
using UnityEngine.UIElements;
/** Rather than trying to undo the .unity-button class, we just remove it from
the element to begin with. */
public class RawButton : Button {
public RawButton() : this(null) { }
public RawButton(Action onClick) : base(onClick) {
@shanecelis
shanecelis / Draggable.cs
Last active Nov 10, 2021
A visual element that is draggable.
View Draggable.cs
using UnityEngine;
using UnityEngine.Scripting;
using UnityEngine.UIElements;
/** A visual element that is draggable. Good example of using the
VisualElement's `tranform.position`.
Credit to Crayz for their code:
https://forum.unity.com/threads/creating-draggable-visualelement-and-clamping-it-to-screen.1017715/
@shanecelis
shanecelis / VisualElementExtensions.cs
Last active Oct 25, 2021
Some extensions to Unity's VisualElement class.
View VisualElementExtensions.cs
/* Original code[1] Copyright (c) 2021 Shane Celis[2]
Licensed under the MIT License[3]
This comment generated by code-cite[4].
[1]: https://gist.github.com/shanecelis/343e3159b6dab44b18b53f47a05fd7c7/edit
[2]: https://twitter.com/shanecelis
[3]: https://opensource.org/licenses/MIT
[4]: https://github.com/shanecelis/code-cite
*/
@shanecelis
shanecelis / DebugOnce.cs
Last active Oct 21, 2021
DebugOnce.Log() logs only once from each source code location.
View DebugOnce.cs
/* Original code[1] Copyright (c) 2021 Shane Celis[2]
Licensed under the MIT License[3]
This comment generated by code-cite[4].
[1]: https://gist.github.com/shanecelis/549ee612b67b13620cd0f9c95e34c853
[2]: https://twitter.com/shanecelis
[3]: https://opensource.org/licenses/MIT
[4]: https://github.com/shanecelis/code-cite
*/
@shanecelis
shanecelis / TriangleElement.cs
Last active Oct 30, 2021
Render a triangle element in addition to the regular rectangular visual element.
View TriangleElement.cs
/* Original code[1] Copyright (c) 2021 Shane Celis[1]
Licensed under the MIT License[1]
This comment generated by code-cite[1].
[1]: https://gist.github.com/shanecelis/7407d0809c114be5d20f089dfe3aa47a
[1]: https://twitter.com/shanecelis
[1]: https://opensource.org/licenses/MIT
[1]: https://github.com/shanecelis/code-cite
*/
View shane-dz60-sc2-qmk-keyboard.json
{
"version": 1,
"notes": "",
"documentation": "\"This file is a QMK Configurator export. You can import this at <https://config.qmk.fm>. It can also be used directly with QMK's source code.\n\nTo setup your QMK environment check out the tutorial: <https://docs.qmk.fm/#/newbs>\n\nYou can convert this file to a keymap.c using this command: `qmk json2c {keymap}`\n\nYou can compile this keymap using this command: `qmk compile {keymap}`\"\n",
"keyboard": "dz60",
"keymap": "shanecelis3",
"layout": "LAYOUT_directional",
"layers": [
[
"KC_ESC",
@shanecelis
shanecelis / RateLimiter.cs
Last active Jul 6, 2020
Limit rate of events based on time for Unity.
View RateLimiter.cs
/* Original code[1] Copyright (c) 2009 Antti Huima[2]
Modified code[3] Copyright (c) 2020 Shane Celis[4]
Licensed under the MIT License[5]
Original code posted to this question[6] and answer[7] on stackoverflow.com.
This comment generated by code-cite[8].
[1]: https://stackoverflow.com/a/668327
[2]: https://stackoverflow.com/users/64376/antti-huima
@shanecelis
shanecelis / boxplot-lines-of-code.sh
Last active Jul 3, 2020
Show a boxplot of lines of code per file on a logscale similar to a plot shown by Uncle Bob.
View boxplot-lines-of-code.sh
#!/bin/bash
# boxplot-lines-of-code
#
# Written by Shane Celis
function usage() {
echo "usage: boxplot-lines-of-code [-h] [-e extension] [-p file.png] [-n name] <directory>" >&2;
echo " -e choose extension of files (\"cs\" by default)" >&2;
echo " -p output to png file instead of terminal" >&2;
echo " -n set plot label (present working directory by default)" >&2;
@shanecelis
shanecelis / coupling.md
Last active Jun 19, 2020
In Defense of Coupling (a programming talk sketch)
View coupling.md

In Defense of Coupling

One of the truisms in software development is that decoupling is good.

Often the most useful patterns I’ve come across are ones that add a new decoupling tool into my toolbox. But coupling exists on a spectrum and tight coupling is not necessarily bad. Tight coupling is often benign and proper as you will see.

So I want to share the many ways that two statements of code may be variously coupled starting from the simplest, tightest coupling to a looser and looser coupling. And some Unity Engine specific decoupling will also be shown, but those can be ignored if you're not familiar with Unity.

Here are the many couplings of statements A and B.

@shanecelis
shanecelis / GridShader.cs
Last active May 26, 2020
Example of how to make your shader accessible in C#.
View GridShader.cs
using UnityEngine;
/** This class communicates directly with the shader to draw grids. The shader's
properties look like this:
Shader "SDF/Grid"{
Properties{
[KeywordEnum(Grid, Cross, Ticks)]
_GridKind ("Kind", Int) = 0
_InsideColor("Inside Color", Color) = (.5, 0, 0, 1)