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
@main | |
struct MyApp: App { | |
// @State var viewStack: [ViewStack] = [] | |
var body: some Scene { | |
WindowGroup { | |
HomeView() | |
// .environment(\.viewStack, $viewStack) | |
} | |
} | |
} |
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
// brute force | |
func funWithAnagrams1(text: [String]) -> [String] { | |
var result = [String]() | |
var lookup = [Int: Set<Character>]() | |
for string in text { | |
if let set = lookup[string.count], | |
set.isSuperset(of: Array(string)) { |
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
struct Promise<T, Error: Swift.Error> { | |
let handler: (Result<T, Error>) -> Void | |
} | |
extension Promise where T == Payload { | |
func fire() -> Result<T, Error> { | |
var result: Result<T, Error>! | |
let semaphore = DispatchSemaphore(value: 0) |
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 UIKit | |
protocol Request { | |
associatedtype Payload: Codable | |
func fire(completion: (Result<Payload, Error>) -> Void) | |
var parameter: [String] { get } | |
} | |
protocol DataPayloadModel: Codable { | |
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
enum Either<A, B> { | |
case left(A) | |
case right(B) | |
} | |
extension Either: Decodable where A: Decodable, B: Decodable { | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
if let a = try? container.decode(A.self) { | |
self = .left(a) |
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 | |
indirect enum Node<Element>: CustomStringConvertible { | |
case leaf(Element) | |
case child(left: Self?, element: Element, right: Self?) | |
var description: String { | |
switch self { | |
case let .child(left: _, element: element, right: _): return String(describing: element) | |
case let .leaf(element) : return String(describing: element) | |
} |
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 | |
indirect enum Node<Element>: CustomStringConvertible { | |
case end(Element) | |
case node(Element, Self) | |
var description: String { | |
switch self { | |
case .end(let element) : return String(describing: element) | |
case .node(let element, _): return String(describing: element) |
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
/** | |
* Retrieves all the rows in the active spreadsheet that contain data and logs the | |
* values for each row. | |
* For more information on using the Spreadsheet API, see | |
* https://developers.google.com/apps-script/service_spreadsheet | |
*/ | |
function readRows() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var rows = sheet.getDataRange(); | |
var numRows = rows.getNumRows(); |
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
private func updateCellAttributes(by attributes: UICollectionViewLayoutAttributes) { | |
var minX = collectionView!.bounds.minX + collectionView!.contentInset.left | |
let maxX = attributes.frame.origin.x | |
if minX > attributes.frame.origin.x + attributes.bounds.width + minimumLineSpacing + collectionView!.contentInset.left { | |
minX = 0 | |
} | |
let finalX = max(minX, maxX) | |
var origin = attributes.frame.origin | |
let deltaX = (finalX - origin.x) / attributes.frame.width |
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 | |
struct Regex { | |
let pattern: String | |
} | |
protocol RegexMatchable : StringProtocol { | |
var regex: Regex { get } | |
func matches(regex: Regex, options: NSRegularExpression.Options) -> [String] | |
func capturedGroups(regex: Regex, options: NSRegularExpression.Options) -> [String] |
NewerOlder