Skip to content

Instantly share code, notes, and snippets.

View JoshuaSullivan's full-sized avatar

Joshua Sullivan JoshuaSullivan

View GitHub Profile
@JoshuaSullivan
JoshuaSullivan / Confusion.cikernel
Created January 26, 2016 19:47
A confusing issue with the CIKernel's sample() method. Assigning the result of samplerTransform() to a variable and then using it in the sample() method breaks everything.
// This works.
kernel vec4 simpleFilter(sampler p)
{
vec2 dc = destCoord();
return sample(p, samplerTransform(p, dc));
}
// This does not. It produces [0, 0, 0, 255] for the first 255 pixels and then [0, 0, 0, 0] thereafter.
kernel vec4 simpleFilter(sampler p)
{
@JoshuaSullivan
JoshuaSullivan / CapturedImageSampler.swift
Created October 1, 2017 01:38
The source code for an object that helps you sample RGB values from ARFrames.
//
// CapturedImageSampler.swift
// ARKitTest
//
// Created by Joshua Sullivan on 9/22/17.
// Copyright © 2017 Joshua Sullivan. All rights reserved.
//
import UIKit
import ARKit
@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 / DataParser.swift
Last active November 21, 2020 17:13
A helper for translating Advent of Code puzzle input into usable values.
import Foundation
/// A type that can be initialized from a string value.
///
public protocol StringInitable {
/// Initialize the object with a string.
///
/// - Note: This operation can fail if the string is not valid for this object type.
///
init?(_ string: String)
@JoshuaSullivan
JoshuaSullivan / ColorAbsoluteDifference.txt
Created October 11, 2020 22:44
Enumerations of the 3 new CoreImage Filters in iOS 14.0
=========================
Color Absolute Difference
=========================
[Availability]
iOS: 14
macOS: 11.0
[Categories]
Color Adjustment, Video, Interlaced, Non-Square Pixels, Still Image, Built-In
@JoshuaSullivan
JoshuaSullivan / EnumExample.swift
Last active April 8, 2020 18:03
Don't use Swift enums to box magic strings! Read the blog post: http://www.chibicode.org/?p=16
enum NotificationNames: String {
case UserDataChanged: "UserDataChangedNotificationName"
case ReceivedAlert: "ReceivedAlertNotificationName"
case PeanutButterJellyTime: "ItsPeanutButterJellyTimeNotificationName"
}
@JoshuaSullivan
JoshuaSullivan / synonym-search.swift
Created March 30, 2020 22:21
Uses the NaturalLanguage framework combined with a thesaurus API to replace adjectives in a sentence with synonyms. This is designed to be run in a Swift Playground.
import UIKit
import NaturalLanguage
import PlaygroundSupport
//: Your secret API key from `https://dictionaryapi.com` goes here.
//: THIS WON'T WORK UNLESS YOU GET A KEY.
let thesaurusKey = ""
//: The string you want to work on.
var testString = "The bright sun set behind the green hills. Thin clouds streaked the red sky."
@JoshuaSullivan
JoshuaSullivan / swift4-kvo-playground.swift
Created May 11, 2018 15:15
Here is a playground demonstrating how to set up Swift 4 KVO.
//: # Setting up Swift 4 KVO
import Foundation
//: This class has a pair of properties that can be observied by KVO.
//: - Note: This class *must* inheret from `NSObject` in order to posess the KVO functionality.
class ObservableClass: NSObject {
/// An observable string property. Note that it most be annotated with both "@objc" (expose the property to the
/// Objective-C runtime) and "dynamic" (enables KVO for the property).
@objc dynamic private(set) var stringProperty: String = "Starting string!"
@JoshuaSullivan
JoshuaSullivan / CForLoopExample.swift
Last active June 27, 2019 16:19
Don't mourn the removal of --, ++ and the C-style for loop from Swift. Read the blog post: http://www.chibicode.org/?p=24
let baseString = "/Documents/"
let words = ["Alpha", "Beta", "Gamma", "Delta"]
var paths : [String] = []
for (var i = 0; i < words.count; ++i) {
let word = words[i]
paths.append("\(baseString)\(word)")
}
print(paths)
@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]