Skip to content

Instantly share code, notes, and snippets.

@capnslipp
capnslipp / swift-build-driverkit
Last active December 29, 2022 17:58
Per-platform `swift-build-…` scripts
#!/usr/bin/env bash
arch="$(uname -m)"
sdk_path="$(xcrun --sdk driverkit --show-sdk-path)"
sdk_version="$(xcrun --sdk driverkit --show-sdk-version)"
echo "Running: " \
swift build -Xswiftc "-sdk" -Xswiftc "${sdk_path}" -Xswiftc "-target" -Xswiftc "${arch}-apple-driverkit${sdk_version}" "$@"
swift build -Xswiftc "-sdk" -Xswiftc "${sdk_path}" -Xswiftc "-target" -Xswiftc "${arch}-apple-driverkit${sdk_version}" "$@"
@capnslipp
capnslipp / DisableWhenAttribute.cs
Last active June 18, 2023 19:47
ShowWhen, HideWhen, EnableWhen, & DisableWhen Attributes for #Unity3D
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @purpose: Shows a field as disabled in Unity's Inspector only when a different method/property/field in the same MonoBehaviour returns/is-equal-to a given value or values.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Add `[DisableWhen(typeof(«MonoBehaviour-sub-type-name»), "«trigger-member-name»", «value-that-the-trigger-member-returns»)]` attribute to a (serializable public) field on your `MonoBehaviour`-class.
/// @intended project path: Assets/Plugins/EditorUtils/DisableWhenAttribute.cs
/// @interwebsouce: https://gist.github.com/capnslipp/9b99f83aa7b80dfb589a5b23e8e0cfa0
using System;
using UnityEngine;
@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 / 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:

@capnslipp
capnslipp / SCNViewController.swift
Last active September 18, 2016 01:49
An adaptable UIViewController subclass for SceneKit
/// @creator: Slipp Douglas Thompson
/// @license: WTFPL
/// @purpose: A `UIViewController` subclass (instantiable from code or XIB/Storyboard) that initializes its `SCNView` using the specified `viewFrame` & `viewOptions`.
/// @why: Because this functionality should be built-into SceneKit.
/// @usage: _FILL_IN_
/// @interwebsouce: https://gist.github.com/capnslipp/6d3e4d3a5f0aeb96eda416774e22dd1f
import UIKit
import SceneKit
@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 / GlobalsStruct.swift
Last active July 23, 2016 00:32
Swift struct private init() test
public struct GlobalsStruct {
public static let aValue = 5
private init() {}
}
@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 / NonDrawingGraphic.cs
Last active February 12, 2024 20:44
A UnityEngine.UI.Graphic subclass that provides only raycast targeting, skipping all drawing.
/// @creator: Slipp Douglas Thompson
/// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
/// @purpose: A UnityEngine.UI.Graphic subclass that provides only raycast targeting, skipping all drawing.
/// @why: Because this functionality should be built-into Unity.
/// @usage: Add a `NonDrawingGraphic` component to the GameObject you want clickable, but without its own image/graphics.
/// @intended project path: Assets/Plugins/UnityEngine UI Extensions/NonDrawingGraphic.cs
/// @interwebsouce: https://gist.github.com/capnslipp/349c18283f2fea316369
using UnityEngine;
using UnityEngine.UI;