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
| final class SharedOperation<T, E: Swift.Error> { | |
| typealias Completion = (Result<T, E>) -> Void | |
| private let queue = DispatchQueue(label: "SharedOperation.queue") | |
| private let execute: (@escaping Completion) -> Void | |
| private var completions: [Completion] = [] | |
| init(_ execute: @escaping (@escaping Completion) -> Void) { | |
| self.execute = execute |
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 | |
| import ImageIO | |
| import UIKit.UIImage | |
| struct ImageMetadata: CustomDebugStringConvertible { | |
| private let properties: NSDictionary | |
| init(raw properties: CFDictionary) { | |
| self.properties = properties | |
| } |
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 ABTests { | |
| static let magicCorrection = ABTest( | |
| settings: UserDefaultsStorage.shared, | |
| keyPath: \.testFlag, | |
| defaultValue: false | |
| ) | |
| } | |
| final class ABTest<T: DefaultsStorageProtocol> { | |
| private let settings: 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
| typealias Handler = (Int) -> Bool | |
| var handlers: [Handler] = [] | |
| func iterate(x: Int) { | |
| // commented code stops at first true | |
| // print(handlers.reduce(false, { $0 || $1(x) })) | |
| // this one iterates over all collection | |
| print(handlers.reduce(false, { $1(x) || $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
| extension UIViewController { | |
| func presentUniqueViewControllerIfNotPresented<T: UIViewController>(_ viewControllerToPresent: () -> T, animated: Bool, completion: (() -> Void)?) { | |
| var presentationHost: UIViewController = self | |
| for viewController in sequence(first: presentationHost, next: { $0.presentedViewController }) { | |
| if viewController is T { | |
| return | |
| } | |
| presentationHost = viewController | |
| } | |
| presentationHost.present(viewControllerToPresent(), animated: animated, completion: completion) |
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 SwiftUI | |
| /* | |
| Rectangle().fill(Color.green).frame(width: 100, height: 30).badge { | |
| Text("100").foregroundColor(Color.white).padding(8) | |
| } | |
| */ | |
| extension View { | |
| func badge<Content: View>(@ViewBuilder content: () -> Content) -> some View { | |
| let badgeContent = content() |
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
| type LRUCache struct { | |
| capacity int | |
| cache map[int]int | |
| priority *list.List | |
| key2node map[int]*list.Element | |
| } | |
| func Constructor(capacity int) LRUCache { | |
| return LRUCache{ | |
| capacity: capacity, |
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
| class Solution { | |
| private func prefix(length: Int, char: (Int) -> Character?) -> [Int] { | |
| var p: [Int] = Array(repeating: 0, count: length) | |
| for i in 1..<length { | |
| var k = p[i-1] | |
| while k > 0 && char(i) != char(k) { | |
| k = p[k-1] | |
| } |
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
| type Blog_LastArticle struct { | |
| state protoimpl.MessageState | |
| sizeCache protoimpl.SizeCache | |
| unknownFields protoimpl.UnknownFields | |
| // id статьи | |
| Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` | |
| // название | |
| Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` | |
| // автор |
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
| public protocol Diffable: Equatable { | |
| var diffId: String { get } | |
| } | |
| public enum Diff { | |
| public enum Change: Hashable { | |
| public typealias Index = Int | |
| case delete(Index) | |
| case insert(Index) |