Skip to content

Instantly share code, notes, and snippets.

@capnslipp
capnslipp / CodeWithDifferingIntentsShouldLookDifferent.swift
Last active September 17, 2022 15:53
My preferred code style for colons in Swift (following good coding habits learned long ago).
import Foundation
class Example {
static func method(label argName: String) -> Void {
NSLog(argName)
}
}
class SuperClass {}
class AType {
@capnslipp
capnslipp / HideInNormalInspectorAttribute.cs
Last active April 12, 2022 09:39
Unity HideInNormalInspector attribute
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @purpose: HideInNormalInspector attribute, to hide fields in the normal Inspector but let them show in the debug Inspector.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Add `[HideInNormalInspector]` as an attribute to public fields you'd like hidden when Unity's Inspector is in “Normal” mode, but visible when in “Debug” mode.
/// @intended project path: Assets/Plugins/EditorUtils/HideInNormalInspectorAttribute.cs
/// @interwebsouce: https://gist.github.com/capnslipp/8138106
using UnityEngine;
@capnslipp
capnslipp / AppDelegateLoudspeaker.cs
Last active December 5, 2019 15:53
iOS AppDelegate UINotifications, in Unity MonoBehaviour scripts
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @why: Because this functionality should be built-into Unity.
/// @intended project path: Assets/Plugins/iOS-Bridge/AppDelegateLoudspeaker.cs
/// @intersource: https://gist.github.com/capnslipp/036f7c98f5ccf42e8428
using UnityEngine;
@capnslipp
capnslipp / RectOffsetPOD.cs
Last active December 5, 2019 15:51
RectOffsetPOD for Unity3D (since UnityEngine.RectOffset likes to throw “ArgumentException: set_left can only be called from the main thread.” if used as a field initialier)
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @why: Because UnityEngine.RectOffset fields should be able to be initialized without throwing ArgumentExceptions (last observed 4.5.2f1).
/// Also, UnityEngine.RectOffset should probably be a struct, not a class.  So a struct form like this is necessary for some software patterns.
/// @intended project path: Assets/Plugins/UnityEngine Extensions/RectOffsetPOD.cs
/// @intersource: https://gist.github.com/capnslipp/87d944e474ca701eca8b
using System;
using UnityEngine;
@capnslipp
capnslipp / KeyedEventActionForwarder.cs
Last active December 5, 2019 15:47
SingleEventAction, KeyedEventActions, & Friends
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @purpose: Forwards keyed events to a KeyedEventActions component elsewhere.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Needs to be put on the same GameObject as the Mecanim Animator component or “legacy” Animation component.
/// Animation events should be configured in the Unity Editor's Animation timeline view or model import settings › Animations tab › Events disclosure (or via the scripting API, I suppose) to call “Function: Action, Parameter String: «your-decided-key-string-for-this-action»”.
/// @intended project path: Assets/Utils/EventAction/KeyedEventActionForwarder.cs
/// @interwebsouce: https://gist.github.com/capnslipp/50db1dc724514bb3db91
using System;
@capnslipp
capnslipp / .gitignore
Created January 30, 2016 23:30
Unity3D .gitignore
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
# Autogenerated VS/MD solution and project files
*.csproj
*.unityproj
*.booproj
*.sln
*.user
@capnslipp
capnslipp / StringIndexOffsetExtensions_Playground.swift
Last active April 20, 2017 02:24
Swift String extensions for shorthand (Ruby-like) indexing
//: Playground - noun: a place where people can play
import Swift
var str = "Hello, playground"
extension String
{
func index(atOffset offset:String.IndexDistance) -> String.Index {
@capnslipp
capnslipp / NilCoalescingAssignmentOperators.swift
Last active February 6, 2017 19:28
Swift extension for `=??` and `??=` nil-coalescing-assignment operators
/// @creator: Slipp Douglas Thompson
/// @license: WTFPL
/// @purpose: A concise operator syntax for assigning to a non-`Optional` from an `Optional`.
/// @why:
/// Sometimes in Swift you want to assign only if the RHS is non-`nil`.
/// Say you have `someArg:Int?` and `_someIvar:Int`. You could use a single-line `if`:
/// `if someArg != nil { _someIvar = someArg! }`
/// Or you could use a ternary or nil-coalesce:
/// `_someIvar = someArg != nil ? someArg! : _someIvar`
/// `_someIvar = someArg ?? _someIvar`
@capnslipp
capnslipp / Full-width content.css
Last active December 2, 2016 20:23
Userstyle CSS for developer.apple.com/reference/*
@-moz-document url-prefix("http://developer.apple.com/reference/"), url-prefix("https://developer.apple.com/reference/") {
.section-content {
margin-left: 4rem !important;
margin-right: 4rem !important;
width: auto !important;
}
.topic-description, .topic-content {
width: auto !important;
float: none !important;

Keybase proof

I hereby claim:

  • I am capnslipp on github.
  • I am capnslipp (https://keybase.io/capnslipp) on keybase.
  • I have a public key whose fingerprint is 6D3E 4ADE 0891 6852 A4AB 52A8 9D4B D9DA FAB9 13D1

To claim this, I am signing this object: