Skip to content

Instantly share code, notes, and snippets.

Avatar

Shane Celis shanecelis

View GitHub Profile
@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)
@shanecelis
shanecelis / Context.cs
Created Apr 20, 2020
Provides a thread-safe global or thread-local context to store a value
View Context.cs
// Java Genetic Algorithm Library.
// Copyright (c) 2017 Franz Wilhelmstötter
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
View .gitmessage
# feature: Add beta sequence.
# ^-----^ ^----------------^
# | |
# | +-> Summary in present tense sentence.
# |
# +-------> Type: binary, chore, doc, excise, feature, fix, hack, legal, refactor,
# style, or test.
@shanecelis
shanecelis / spider-eyes.svg
Created Sep 26, 2019
Encode the left half of spider eye patterns in simple shapes. See tweet: https://twitter.com/shanecelis/status/1177076559301287937
View spider-eyes.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shanecelis
shanecelis / TextImporter.cs
Last active Aug 21, 2019
Import files with the extensions you specify as text assets in Unity 3D.
View TextImporter.cs
/* Original code[1] Copyright (c) 2019 Shane Celis[2]
Licensed under the MIT License[3]
[1]: https://gist.github.com/shanecelis/5c38ce90cca057e857f415108f5ac75a
[2]: https://github.com/shanecelis
[3]: https://opensource.org/licenses/MIT
*/
using UnityEngine;
using UnityEditor.Experimental.AssetImporters;
View magit-status-parent.el
(defun magit-status-parent ()
"Open the magit status of a parent git repository. Useful for
dealing with submodules. Suggest binding to SPC g p for Spacemacs.
(spacemacs/set-leader-keys \"gp\" 'magit-status-parent)
"
(interactive)
(let* ((child-directory (magit-toplevel default-directory))
(parent-directory (and child-directory
(magit-toplevel (file-name-directory
@shanecelis
shanecelis / PriorityPhysicsRaycaster.cs
Last active Jul 5, 2019
Prioritized raycaster for casting against 3D Physics components. https://twitter.com/shanecelis/status/1146822575978373120
View PriorityPhysicsRaycaster.cs
/* Original code[1] Copyright (c) 2019 Shane Celis[2]
Licensed under the MIT License[3]
This comment generated by code-cite[4].
[1]: https://gist.github.com/shanecelis/5379ed7c634222dc979e09e728ef0a6c
[2]: https://github.com/shanecelis
[3]: https://opensource.org/licenses/MIT
[4]: https://github.com/shanecelis/code-cite
*/
You can’t perform that action at this time.