Skip to content

Instantly share code, notes, and snippets.

View JoshuaSullivan's full-sized avatar

Joshua Sullivan JoshuaSullivan

View GitHub Profile
@JoshuaSullivan
JoshuaSullivan / Appearance Proxy iOS 9.1.md
Last active August 13, 2016 17:26
Properties and methods of UIKit classes which expose customization via UIAppearance.

UIActivityIndicatorView

@property (nullable, readwrite, nonatomic, strong) UIColor *color NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

UIBarButtonItem

- (void)setBackgroundImage:(nullable UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

- (nullable UIImage *)backgroundImageForState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
@JoshuaSullivan
JoshuaSullivan / ProtocolsAndInheritance.swift
Last active October 28, 2016 18:27
This playground demonstrates a potentially confusing gotcha when using protocols that have default method implementations along with class inheritance.
//: # Protocols and Inheritance
//: This playground demonstrates a gotcha in the use of protcols with default
//: method implementations along with class inheritance.
import UIKit
//: This protocol defines a single method that takes an `Int` and returns an `Int`.
protocol Doable {
func doSomething() -> Int
}
@JoshuaSullivan
JoshuaSullivan / human.swift.motemplate
Last active November 12, 2016 20:55
Better mogenerator Swift templates!
import Foundation
@objc(<$managedObjectClassName$>)
public class <$managedObjectClassName$>: _<$managedObjectClassName$> {
// Custom logic goes here.
}
@JoshuaSullivan
JoshuaSullivan / RepeatingSequence.swift
Last active November 17, 2016 17:14
This is a simple Sequence type that accepts an array and sequentially returns the elements, looping back to the first as needed until the required number of elements has been generated.
//: # RepeatingSequence
import Swift
import Foundation
struct RepeatingSequence<T>: Sequence {
/// The Collection that we base our sequence on. We use a Collection and not
/// another Sequence because Sequences are not guaranteed to be repeatedly iterated.
let data: AnyCollection<T>
@JoshuaSullivan
JoshuaSullivan / RepeatingSequence.swift
Created December 8, 2016 15:49
A new Sequence type that returns a repeating sequence of values.
/// The RepeatingSequence accepts a collection and returns the values sequentially until the
/// final element is returned, at which point the sequence wraps around to the first element
/// of the collection and continues from there.
struct RepeatingSequence<T>: Sequence {
/// The Collection that we base our sequence on. We use a Collection and not
/// another Sequence because Sequences are not guaranteed to be repeatedly iterated.
let data: AnyCollection<T>
/// We can optionally specify a maximum number of iterations. This is necessary
@JoshuaSullivan
JoshuaSullivan / LatticePaths.swift
Last active January 16, 2017 01:45
Code Challenge #54 - Lattice Paths (Playground w/ markup)
//: # Code Challenge #54
//: ## Lattice Paths
//:
//: It may not be the most clever or direct solution, but the problem can be modeled
//: using Pascal's Triangle (https://en.wikipedia.org/wiki/Pascal's_triangle). For a square grid
//: of dimension `N`, the number of paths can be found at the 'central' position of row `2 * N + 1` of
//: Pascal's Triangle.
import Swift
/// The size of the grid, measured in nodes per edge.
@JoshuaSullivan
JoshuaSullivan / slit_scan.pde
Created April 20, 2017 15:57
A sketch implementing a simple slit-scan camera from the user's webcam or other attached video source.
// Slit-scan Camera
// ©2016 Joshua Sullivan
//
// This sketch implements a simple time-slit camera. Each row of the video is offset
// in time by one frame more than the previous row. So, the top row is real-time and
// the bottom row is 240 frames ago.
//
// We're using an optimized storage mechanism where we are storing N + 1 samples for each row
// of the video frame, where N is the index of the row, from 0 to FRAME_HEIGHT - 1. This means
// index[0] holds 1 row of data, index[1] holds 2, and so on until index[239] holds 240.
@JoshuaSullivan
JoshuaSullivan / Packet.proto
Last active May 11, 2017 02:28
Files related to my blog post about communicating over BLE using protocol buffers.
syntax = "proto3";
message Packet {
float time = 1;
sint32 rx = 2;
sint32 ry = 3;
sint32 rz = 4;
}
@JoshuaSullivan
JoshuaSullivan / pillars.pde
Last active July 3, 2017 18:44
Pillars lie beneath the surface, popped up by frequent puffs of air…
final int PILLAR_ORDER = 6;
final float PILLAR_WIDTH = 40.0;
final float PILLAR_HEIGHT = 20.0;
final float PILLAR_SPACING = 2.0;
final float GRAVITY = -1.0;
final float ELASTICITY = -0.6;
final float MAX_HEIGHT = 500.0;
@JoshuaSullivan
JoshuaSullivan / pillars_chroma.pde
Created July 4, 2017 17:48
The pillars have undergone chromatic infusion…
final int PILLAR_ORDER = 6;
final float PILLAR_WIDTH = 40.0;
final float PILLAR_HEIGHT = 20.0;
final float PILLAR_SPACING = 2.0;
final float GRAVITY = -1.0;
final float ELASTICITY = -0.6;
final float MAX_HEIGHT = 500.0;