Skip to content

Instantly share code, notes, and snippets.

///
/// Adds logging to all functions in a JS object.
///
/// Backbone usage example:
/// return Backbone.View.extend({ ... });
/// becomes:
/// return Backbone.View.extend(addLogs({ ... }));
/// and all method invocations are now logged to the console.
///
function addLogs(obj) {
@jaburns
jaburns / cd_to_script.sh
Created June 16, 2016 21:50
cd to the location of the script being run
cd "$(dirname "${BASH_SOURCE[0]}")"
@jaburns
jaburns / findrefs.sh
Last active September 8, 2016 04:23
Find scene and prefab references to scripts in Unity.
#!/usr/bin/env bash
#
# Run from the project root. Pass the full name of a script, or substring of the names of the scripts to check.
#
# Example
# $) ./findrefs.sh BackgroundCamera
# Finding matches for script Assets/Scripts/Camera/BackgroundCamera.cs.meta ...
# Assets/Prefabs/CaveBGCamera.prefab: m_Script: {fileID: 11500000, guid: 7e63acfee367c4314852b87218149bd3, type: 3}
# Assets/Prefabs/ForestBGCamera.prefab: m_Script: {fileID: 11500000, guid: 7e63acfee367c4314852b87218149bd3, type: 3}
#
@jaburns
jaburns / BumperZapper.cs
Last active November 16, 2015 22:11
Type-safe implementation of Unity's SendMessage
using UnityEngine;
public class BumperZapper : MonoBehaviour
{
Rigidbody2D _rb;
void Awake()
{
_rb = GetComponent<Rigidbody2D>();
}
using UnityEngine;
using UnityEditor;
static public class PolygonHolePunchMenuItem
{
[MenuItem("Tools/PolygonCollider2D Punch Hole")]
static public void PolygonHolePunchMenuItem_Click()
{
if (!Selection.activeGameObject) return;
var collider = Selection.activeGameObject.GetComponent<PolygonCollider2D>();
@jaburns
jaburns / struniq.sh
Last active November 16, 2015 22:34
Pass in a string, exits 0 if all characters are unique.
#!/usr/bin/env bash
echo "$1" | fold -w 1 | sort | tee /tmp/struniq | uniq | cmp -s - /tmp/struniq
@jaburns
jaburns / playground.html
Created August 25, 2015 18:01
Shim for messing around with effects
<!DOCTYPE html>
<html>
<body>
<canvas id="paper" width="1024" height="768"></canvas>
<script>
// ---------------------------------------------------------------------------
var canvas = document.getElementById("paper");
var ctx = canvas.getContext("2d");
var mouse = {}, keys = {};
canvas.addEventListener('mousemove', function(e) {
@jaburns
jaburns / CubicSplineWalker.cs
Created August 15, 2015 23:19
Estimates the length of a cubic Bezier spline and provides an interface to walk it at a constant speed.
using UnityEngine;
using System;
using System.Collections.Generic;
public class CubicSplineWalker
{
readonly Vector2 _anchor0;
readonly Vector2 _control0;
readonly Vector2 _control1;
readonly Vector2 _anchor1;
@jaburns
jaburns / StarlingAtlasSlicer.cs
Last active August 29, 2015 14:20
Starling sprite animation atlas slicer for Unity
using System;
using System.Collections.Generic;
using System.Xml;
using UnityEditor;
using UnityEngine;
public class StarlingAtlasSlicer
{
[MenuItem("CONTEXT/TextureImporter/Slice Sprite Using XML")]
static public void SliceUsingXML(MenuCommand command)
@jaburns
jaburns / gdrive-invert-icons
Created March 30, 2015 21:04
Force inverted tray icons for OSX Google Drive
#!/usr/bin/env bash
cd /Applications/Google\ Drive.app/Contents/Resources
for file in $(find . -depth 1 | grep 'inverse.*png'); do
echo "Fixing $file ..."
cp "$file" "$(printf "$file" | sed 's/-inverse//')"
done
echo 'Done!'