Skip to content

Instantly share code, notes, and snippets.

View SaganRitual's full-sized avatar
Realizing daily I'm not a mathematician

Rob Bishop SaganRitual

Realizing daily I'm not a mathematician
View GitHub Profile
SaganRitual / ContentView.swift
Created December 15, 2021 22:43
One way of passing state from parent to child
// We are a way for the cosmos to know itself. -- C. Sagan
import SwiftUI
class ChildState: ObservableObject {
@Published var childData = 0
struct Parent: View {
@State var parentData = 0
SaganRitual / Overload2D.swift
Created March 25, 2019 19:44
Arithmetic and conversions for CGPoint, CGSize, and CGVector. These make the code much more readable and writable, at least for me.
import CoreGraphics
/// Arithmetic extensions for CGPoint, CGSize, and CGVector.
/// All of the operators +, -, *, /, and unary minus are supported. Where
/// applicable, operators can be applied to point/size/vector + point/size/vector,
/// as well as point/size/vector + CGFloat and CGFloat + point/size/vector.
protocol Overload2D {
/// Really for internal use, but publicly available so the unit tests can use them.
var a: CGFloat { get set }
var b: CGFloat { get set }
SaganRitual / MoreBadKarmaFromGenerics.swift
Created March 13, 2019 14:33
I'm not a bad person. Why must the universe punish me so with Swift generics?
struct ProtoOrder<T> {
var quantity: T
init(_ quantity: T) { self.quantity = quantity }
protocol ItemProtocol {
associatedtype HowCounted: Numeric
typealias Order = ProtoOrder<HowCounted>
import SpriteKit
import GameplayKit
class GameScene: SKScene {
static var shared: GameScene?
var frameCount = 0
var bigSprite: SKSpriteNode?
var bigSpriteIsSetup = false
var spriteTexture: SKTexture?
SaganRitual / Box.swift
Created February 4, 2019 14:37
SpriteKit starter, draw grid, detect touches on sprites, cause neighboring sprites to react
import Foundation
import SpriteKit
class Box {
let sprite: SKShapeNode
let cellAddress: XYPair
var position: CGPoint {
get { return sprite.position }
set { sprite.position = newValue }
SaganRitual / Box.swift
Created January 29, 2019 15:36
Another SpriteKit starter, some examples of how to use physics and actions
import Foundation
import SpriteKit
func getColorName(_ color: NSColor) -> String {
switch color {
case .black: return "black"
case .white: return "white"
case .gray: return "gray"
case .red: return "red"
case .green: return "green"
SaganRitual / GameScene.swift
Created January 29, 2019 13:40
In case it helps anyone, a SpriteKit starter with physics turned on and a couple of sprites demonstrating collision detection
import SpriteKit
import GameplayKit
class GameScene: SKScene {
var box1: SKShapeNode?
var box2: SKShapeNode?
override func didMove(to view: SKView) {
let b1 = SKShapeNode(circleOfRadius: 50.0)
SaganRitual /
Created January 21, 2019 18:16 — forked from ryanchang/
LLDB Cheat Sheet

LLDB Cheat Sheet

A complete gdb to lldb command map.

Print out

  • Print object
(lldb) po responseObject
(lldb) po [responseObject objectForKey@"state"]
  • p - Print primitive type
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
SaganRitual / PricelessGenericBuilder.swift
Last active October 31, 2018 21:36
A generic builder that allows me to inject dependencies into the built objects
// With gratitude to David Harris
// for his article on making generic factories. I might keep some of my hair.
import Foundation
open class Builder<DependencyType> {
public typealias DependencyCreator = () -> DependencyType