Skip to content

Instantly share code, notes, and snippets.

View JoshuaSullivan's full-sized avatar

Joshua Sullivan JoshuaSullivan

View GitHub Profile
@JoshuaSullivan
JoshuaSullivan / pillars_order.pde
Created July 6, 2017 02:13
Control systems coming online. Order is being established…
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;
@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 / 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 / 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 / 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 / JTSSwiftTweener.swift
Last active June 22, 2021 03:37
A tweening library to animate arbitrary numerical values.
//
// JTSSwiftTweener.swift
// JTSSwiftTweener
//
// Created by Joshua Sullivan on 12/10/16.
// Copyright © 2016 Josh Sullivan. All rights reserved.
//
import UIKit
@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 / ObfuscationDecoder.swift
Last active May 6, 2019 11:48
This playground shows how to use a RepeatingSequence type to create strong string obfuscation using a multi-byte nonce.
import Foundation
public struct ObfuscationDecoder {
public enum DeobfuscationError: Error {
case invalidStringBytes
}
/// The multi-byte nonce used to encode strings.
private static let nonce: [UInt8] = [199, 152, 254, 45, 85, 241, 134, 185, 22, 249, 182, 208, 43, 176, 143, 252]
@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
}