Or: “Everybody likes being given a glass of water.”
By Merlin Mann.
It's only advice for you because it had to be advice for me.
| extension Result { | |
| public func `catch`(_ handler: () throws -> Success) -> Result<Success, Error> { | |
| flatMapError { _ in | |
| .init { try handler() } | |
| } | |
| } | |
| public func `catch`(_ handler: (Failure) throws -> Success) -> Result<Success, Error> { | |
| flatMapError { error in | |
| .init { try handler(error) } |
| private let configKey = CodingUserInfoKey(rawValue: UUID().uuidString)! | |
| private struct ConfigWrapper<Value> { | |
| let value: Value | |
| } | |
| extension ConfigWrapper: Decodable where Value: DecodableWithConfiguration { | |
| init(from decoder: Decoder) throws { | |
| let config = decoder.userInfo[configKey]! as! Value.DecodingConfiguration | |
| value = try Value(from: decoder, configuration: config) |
| // Type-safe State Machine with Phantom Type May 2022 @AtarayoSD | |
| import Foundation | |
| protocol State {} | |
| // Transitions | |
| protocol TransferableToB {} | |
| protocol TransferableToC {} | |
| protocol TransferableToD {} |
| import UIKit | |
| extension Array where Element == NSLayoutConstraint { | |
| /// Activates each constraint in an array of `NSLayoutConstraint`. | |
| /// | |
| /// Example usage: `[view.heightAnchor.constraint(equalToConstant: 30), view.widthAnchor.constraint(equalToConstant: 30)].activate()` | |
| func activate() { | |
| NSLayoutConstraint.activate(self) | |
| } |
| import UIKit | |
| import AVFoundation | |
| class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { | |
| let tableView = UITableView(frame: .zero, style: .plain) | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| tableView.register(PlayerTableViewCell.self, forCellReuseIdentifier: "PlayerCell") |
| #!/bin/sh | |
| pids=`ps axo pid,command | grep CoreSimulator | grep -v "grep CoreSimulator" | cut -c 1-5` | |
| if [ "$1" = "go" ]; then | |
| kill -9 $pids | |
| elif [ "$1" = "echo" ]; then | |
| echo $pids | |
| else | |
| pid_param=`echo $pids | tr -s ' ' ','` |