This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| enum ParenthesisType: CaseIterable { | |
| case round | |
| case square | |
| case curly | |
| var open: Character { | |
| switch self { | |
| case .round: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func longestCommonPrefix(_ strs: [String]) -> String { | |
| var shortest = Int.max | |
| let charArrays = strs.map { (string) -> [Character] in | |
| let array = Array(string) | |
| shortest = min(shortest, array.count) | |
| return array | |
| } | |
| var outputChars = [Character]() | |
| for i in 0..<shortest { | |
| let ithChars = charArrays.map { $0[i] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let romanMapping: [String: Int] = [ | |
| "I" : 1, | |
| "V" : 5, | |
| "X" : 10, | |
| "L" : 50, | |
| "C" : 100, | |
| "D" : 500, | |
| "M" : 1000 | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // PickerHandler.swift | |
| // Created by Jake Hawken on 8/27/19. | |
| import Foundation | |
| import UIKit | |
| class PickerHandler<T: CustomStringConvertible> { | |
| typealias ItemSelectionCallback = (T)->() | |
| private let implementation: PickerHandlerImplementation<T> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ProbabilityTree.swift | |
| // Created by Jake Hawken on 8/4/19. | |
| // Copyright © 2019 Jake Hawken. All rights reserved. | |
| import Foundation | |
| // TODO: genericize so that this can be used for things other than strings | |
| class ProbabilityTree { | |
| private let rootNode = Node(word: "", parent: nil) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| public class PropertyBox<T> | |
| { | |
| private T value; | |
| public Action<T> didSet; | |
| public Action<T,T> willSet; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftyJSON | |
| extension JSON { | |
| func parseTo<T: Codable>() -> T? { | |
| guard let data = try? rawData(options: .prettyPrinted) else { | |
| return nil | |
| } | |
| let decoder = JSONDecoder() | |
| return try? decoder.decode(T.self, from: data) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| protocol PrettyPrintable { | |
| func prettyPrinted() -> String | |
| func prettyPrintToConsole() | |
| } | |
| extension PrettyPrintable { | |
| func prettyPrintToConsole() { | |
| let pretty = prettyPrinted() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UIView { | |
| func firstSuperview<T: UIView>(ofType type: T.Type) -> T? { | |
| guard let superview = superview else { | |
| return nil | |
| } | |
| if let superViewAsT = superview as? T { | |
| return superViewAsT | |
| } | |
| return superview.firstSuperview(ofType: type) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static func -=(lhs: inout String, rhs: String) { | |
| guard lhs.hasSuffix(rhs) else { | |
| return | |
| } | |
| guard let range = lhs.range(of: rhs, options: [.backwards], range: nil, locale: nil) else { | |
| return | |
| } | |
| lhs = lhs.replacingCharacters(in: range, with: "") | |
| } |