Skip to content

Instantly share code, notes, and snippets.

View seancatkinson's full-sized avatar

Sean Atkinson seancatkinson

View GitHub Profile
@seancatkinson
seancatkinson / BetterComposableURLMatching.swift
Created August 19, 2018 19:48
An experiment using for matching URLs against patterns. A refined version of https://gist.github.com/seancatkinson/d0f755967e79fc604aa591e69a55ebbd
//: Playground - noun: a place where people can play
import Foundation
// protocol representing the individual components to be matched against a URL
protocol URLComponentMatching {
func matches(_ url:URL) -> Bool
}
// logic for comparing arrays of patterns against a URL
@seancatkinson
seancatkinson / ComposableURLMatching.swift
Created August 19, 2018 19:47
An experiment using URLComponents for matching URLs against patterns
//: Playground - noun: a place where people can play
import Foundation
// function to do implicit and explicit compare of a value to a pattern
func equalIfPresent<ComparedType>(pattern:ComparedType?, value:ComparedType?) -> Bool where ComparedType:Equatable {
// we need a pattern else there is nothing to match against
// if we don't have a pattern to compare to, it implicitly matches
guard let pattern = pattern else { return true }

Keybase proof

I hereby claim:

  • I am seancatkinson on github.
  • I am seancatkinson (https://keybase.io/seancatkinson) on keybase.
  • I have a public key ASBFkOOrBhVv6ThU9jwirMKcV9_lQDmQUy07V-i5rlSX1Qo

To claim this, I am signing this object:

@seancatkinson
seancatkinson / CFTypeRef
Created February 28, 2018 17:57
playing with CFTypeRef and keychain APIs
#pragma mark - Public Methods
+ (NSData*) valueForQuery:(NSDictionary*)query error:(NSError**)error {
// adjust the query so that we return a single data result
NSMutableDictionary *mutableQuery = [query mutableCopy];
[mutableQuery setObject:@YES
forKey:(__bridge id)kSecReturnData];
[mutableQuery setObject:(__bridge id)kSecMatchLimitOne
forKey:(__bridge id)kSecMatchLimit];
@seancatkinson
seancatkinson / problem.swift
Last active November 11, 2017 11:49
Swift Generic Constraints
protocol Foo {
associatedtype Bar
func process(bar:Bar)
}
class MyFoo<T>: Foo {
func process(bar: T) {}
}
@seancatkinson
seancatkinson / .swiftlint.yml
Created July 16, 2017 20:31
Basic swiftlint.yml WIP
disabled_rules: # rule identifiers to exclude from running
opt_in_rules:
- attributes
- closure_end_indentation
- closure_spacing
- conditional_returns_on_newline
- empty_count
- explicit_init
#- explicit_top_level_acl # enable this in libraries only, not in applications
@seancatkinson
seancatkinson / .bash_profile
Created September 17, 2016 16:13 — forked from natelandau/.bash_profile
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
// Who let the dogs out?
enum Result <Value, Error:ErrorType> {
case Success(Value)
case Failure(Error)
}
enum DogReleasingError : ErrorType {
case LockedDoor
case NoDogs
case Other(reason:String)
/**
A generic function that swaps to values of the same type
- parameter a: the value to placed in variable b
- parameter b: the value to be placed in variabe a
*/
func swapTwoValues <T>(inout a:T, inout _ b:T) {
let temp = a
a = b
@seancatkinson
seancatkinson / GettingStartedWithSwift-Protocols.swift
Created January 13, 2016 00:04
Final example code accompanying my Getting Started With Swift article on protocols
// Protocols
protocol Speaking {
func speak() -> String
}
protocol Hunting {
func hunt()
}
protocol Foraging {