Skip to content

Instantly share code, notes, and snippets.

View geor-kasapidi's full-sized avatar
💤
#

Geor Kasapidi geor-kasapidi

💤
#
View GitHub Profile
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
import Foundation
import ImageIO
import UIKit.UIImage
struct ImageMetadata: CustomDebugStringConvertible {
private let properties: NSDictionary
init(raw properties: CFDictionary) {
self.properties = properties
}
enum ABTests {
static let magicCorrection = ABTest(
settings: UserDefaultsStorage.shared,
keyPath: \.testFlag,
defaultValue: false
)
}
final class ABTest<T: DefaultsStorageProtocol> {
private let settings: T
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 }))
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)
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()
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,
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]
}
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"`
// автор
@geor-kasapidi
geor-kasapidi / Diff.swift
Created February 27, 2020 19:45
Diff example
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)