Skip to content

Instantly share code, notes, and snippets.

@bppr
bppr / string-extensions.swift
Last active August 29, 2015 14:23
Nice things for Swift's strings without using Foundation
extension String {
var length: Int { get { return characters.count } }
var first: Character { get { return self[self.startIndex] }}
var last: Character { get { return self[self.endIndex.predecessor()] }}
func contains(fragment: String) -> Bool {
return self.indexOf(fragment) != nil
}
func indexOf(fragment: String) -> String.Index? {
@bppr
bppr / Ratio.swift
Created February 8, 2018 16:16
Ratio.swift
fileprivate func gcd(_ a: Int, _ b: Int) -> Int {
return b == 0 ? a : gcd(b, a % b)
}
fileprivate func abs(_ n: Int) -> Int {
return n > 0 ? n : -n
}
struct Ratio {
let numerator: Int
@bppr
bppr / keybase.md
Created March 26, 2018 20:00
keybase.md

Keybase proof

I hereby claim:

  • I am bppr on github.
  • I am bppr (https://keybase.io/bppr) on keybase.
  • I have a public key ASASvSupq_C9i252FuT4PUuYKNTNu_XJdqTLdGWbcYNypQo

To claim this, I am signing this object:

@bppr
bppr / travelogue.md
Last active August 1, 2018 13:28
travelogue

National Parks

  • Badlands, SD
  • Yellowstone, WY
  • Grand Teton, WY
  • Cuyahoga Valley, OH
  • Great Smoky Mountain, TN/NC
  • Blue Ridge Parkway, NC

National Forests

  • Black Hills, SD
@bppr
bppr / example.swift
Last active May 24, 2019 15:41
swift protocols with associations
protocol Features {}
protocol ProFeatures: Features {}
protocol Account {
associatedtype FeatureType
var features: FeatureType { get set }
}
class ProAccount<T: Features>: Account {
typealias FeatureType = T