This file contains 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 Collection { | |
subscript(safeIndex index: Index) -> Element? { | |
return indices.contains(index) ? self[index] : nil | |
} | |
} | |
extension Array where Element: Collection, Element.Index == Int { | |
func samples(x: Int, y: Int, offset: Int) -> [Element.Element] { | |
var rows: [Element?] = [] |
This file contains 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
public extension Optional { | |
func asyncMap<T>( | |
transform: (Wrapped) async throws -> T | |
) async rethrows -> T? { | |
guard case let .some(value) = self else { | |
return nil | |
} | |
return try await transform(value) | |
} | |
} |
This file contains 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
public struct NilError: Error { | |
public let file: String | |
public let line: UInt | |
public let column: UInt | |
public let function: String | |
public init( | |
file: String = #fileID, | |
line: UInt = #line, | |
column: UInt = #column, |
This file contains 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 UIKit | |
public protocol BlockConfigurable {} | |
extension NSObject: BlockConfigurable {} | |
extension BlockConfigurable {} | |
public extension UIView { | |
@discardableResult |
This file contains 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 CGRect { | |
mutating func moveOriginToFitIn(_ rect: CGRect) { | |
origin = .init( | |
x: min( | |
max(rect.minX, minX), | |
rect.maxX - width | |
), | |
y: min( | |
max(rect.minY, minY), | |
rect.maxY - height |
This file contains 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
public extension Bool { | |
func map<T>( | |
_ closure: () -> T?, | |
else: (() -> T?)? = nil | |
) -> T? { | |
self ? closure() : `else`?() | |
} | |
func map<T>( | |
_ closure: () -> T, |
This file contains 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 PlaygroundSupport | |
import UIKit | |
let baseURL = "https://api.github.com/repos/my_repo_owner/my_repo/actions/runs" | |
let auth = ["Authorization": "Token my_token"] | |
enum ResponseError: Error { | |
case invalidURL | |
case httpError(Error) | |
case badResponse(HTTPURLResponse) |
This file contains 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
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
pull_request: | |
types: [opened, synchronize, reopened] |
This file contains 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 runTest() -> Bool { | |
let random = Int.random(in: 0...100) | |
var coins = Array(repeating: true, count: 20) + Array(repeating: false, count: random) | |
let mask = coins | |
coins.shuffle() | |
var result: [Bool] = [] | |
for (coin, flip) in zip(coins, mask) { | |
result.append(coin != flip) | |
} |
This file has been truncated, but you can view the full file.
This file contains 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
{ | |
"geofire" : { | |
"-KARkcAtgda-pqdqSSkm" : { | |
".priority" : "dpz8b2rtj8", | |
"g" : "dpz8b2rtj8", | |
"l" : [ 43.727821, -79.431598 ] | |
}, | |
"-KARkcAvzGE_TyRF7MZ5" : { | |
".priority" : "dr5rvp6hzm", | |
"g" : "dr5rvp6hzm", |
NewerOlder