Skip to content

Instantly share code, notes, and snippets.

View RyanNielson's full-sized avatar

Ryan Nielson RyanNielson

View GitHub Profile
@RyanNielson
RyanNielson / TransformEditor2D.cs
Last active February 3, 2020 11:23
A custom Inspector for Unity's Transform component to make it nicer when working on 2D games.
using UnityEngine;
using UnityEditor;
[CanEditMultipleObjects, CustomEditor(typeof(Transform))]
public class TransformEditor2D : Editor
{
public override void OnInspectorGUI()
{
Transform transform = (Transform)target;
@RyanNielson
RyanNielson / PixelSnapped.shader
Created August 14, 2015 23:31
A shader to snap sprite vertices to a virtual pixel grid determined by PixelsPerUnit
Shader "Sprites/PixelSnapped"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[PerRendererData] _PixelsPerUnit ("Pixels Per Unit", Float) = 16
}
SubShader
using UnityEngine;
/// <summary>
/// Letterboxes the view to the aspect ratio given in targetSize.
/// If stretch is true, view fills camera with given aspect ratio.
/// If stretch is false, view is letterboxed to sizes that are only *1, *3, *3, etc of targetSize.
/// </summary>
[ExecuteInEditMode, RequireComponent(typeof(Camera))]
public class LetterboxAndScale : MonoBehaviour
{
using UnityEngine;
using System.Collections;
public class LifeSpan : MonoBehaviour
{
[SerializeField, Tooltip("How long this GameObject lives before dying, 0 = forever.")]
private float initialLifeSpan = 0;
private IEnumerator lifeSpanExpiredCoroutine = null;
@RyanNielson
RyanNielson / autocomplete ssh hosts
Last active August 29, 2015 14:10
Autocomplete ssh hosts using tab
complete_ssh_hosts ()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
@RyanNielson
RyanNielson / fillable.md
Last active August 29, 2015 14:06
Idea for multiple fillable options

This is a suggestion to improve fillable to make it easier to assign multiple values for fillable. This would be useful if a site had different roles, for example if an admin can edit things a user cannot.

To implement this it should just be a matter of a few changes by adding an extra parameter to a few methods for the fillable key, and passing this along when fillable is checked to check against the correct array.

Below is an example of what using this feature would look like.

@RyanNielson
RyanNielson / html_css_styleguide.md
Created July 9, 2014 13:20
HTML/CSS Styleguide

Style

  • User underscores in ID names.
<div id="cool_div"></div>
  • User dashes in class names.
@RyanNielson
RyanNielson / php_styleguide.md
Last active August 29, 2015 14:03
PHP Styleguide

These are some guidelines I came up with that we should follow to ensure consistency and readability in our codebase. This guide is a combination of other PHP style guides, Laravel expectations, and preferences. Things like function length and line length aren't required, just sometimes good to follow. Most of these rules can be setup in your editor so you don't have to worry about them.

Coding Style

  • Use soft-tabs with a 4 space indent.
  • Try to keep lines 100 characters long or less.
  • Try to keep functions 10-20 lines long. Don't be afraid to break them into smaller functions, it makes code easier to understand most of the time.
  • Remove all trailing whitespace on lines.
  • End each file with a blank newline.
  • Use spaces around operators, after commas.
@RyanNielson
RyanNielson / TrackTargets.cs
Created March 30, 2014 20:15
A orthographic camera script for Unity that keeps all targets in frame by adjusting orthographic size and camera position.
using UnityEngine;
public class TrackTargets : MonoBehaviour {
[SerializeField]
Transform[] targets;
[SerializeField]
float boundingBoxPadding = 2f;
@RyanNielson
RyanNielson / rrmdir.php
Created March 24, 2014 12:20
Function to recursively remove a directory and all of its contents.
function rrmdir($dir) {
foreach(glob($dir . '/*') as $file) {
if(is_dir($file))
$this->rrmdir($file);
else
unlink($file);
}
rmdir($dir);
}