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
@inlinable func trampolineToMain(_ function: @escaping @autoclosure ()->()) -> Bool { | |
if Thread.isMainThread { | |
return false | |
} else { | |
DispatchQueue.main.async { | |
function() | |
} | |
return true | |
} | |
} |
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
find . -type d \( -path ./Pods -o -path ./Vendor \) -prune -o \( -iname \*.m -o -iname \*.mm -o -iname \*.h -o -iname \*.swift \) -print0 | xargs -0 wc -l |
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 Foundation | |
var RUNS = 10 | |
var COUNT = 10_000_000 | |
// Extensions for prints | |
extension Sequence where Element: BinaryFloatingPoint { | |
func average() -> Element { | |
var i: Element = 0 |
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 Foundation | |
// Debouncer | |
func debounce(delay: TimeInterval, action: @escaping (String)->Void) -> (String)->Void { | |
let callback = DebounceCallback(action) | |
var timer: Timer? | |
return { arg in | |
if let timer = timer { timer.invalidate() } // invalidate the last timer | |
timer = Timer(timeInterval: delay, | |
target: callback, |
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
// Utils for bit operations | |
enum Bit { | |
case zero, one | |
func asInt() -> Int { self == .one ? 1 : 0} | |
} | |
// to bytes(UInt8) | |
func bitsToBytes(bits: [Bit]) -> [UInt8] { | |
let numBits = bits.count | |
let numBytes = (numBits + 7)/8 | |
var bytes = [UInt8](repeating: 0, count: numBytes) |
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
// | |
// UUID4.swift | |
// | |
// Created by exey on 17.03.2020. | |
// Copyright © 2020 Exey Panteleev. All rights reserved. | |
// | |
extension UInt8 { | |
func hexString(padded:Bool = true) -> String { | |
let dict:[Character] = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"] |
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
// | |
// Date.swift | |
// | |
// Created by Exey Panteleev on 29.08.2019. | |
// Copyright © 2019 Exey Panteleev. All rights reserved. | |
// | |
import Foundation | |
let ANY_VALID_DATE: String = #"(\b(0?[1-9]|[12]\d|30|31)[^\w\d\r\n:](0?[1-9]|1[0-2])[^\w\d\r\n:](\d{4}|\d{2})\b)|(\b(0?[1-9]|1[0-2])[^\w\d\r\n:](0?[1-9]|[12]\d|30|31)[^\w\d\r\n:](\d{4}|\d{2})\b)"# |
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 SwiftUI | |
private struct LazyView<Content: View>: View { | |
let build: () -> Content | |
init(_ build: @autoclosure @escaping () -> Content) { | |
self.build = build | |
} | |
var body: Content { | |
build() |
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 UITabBar { | |
/// // TabBar Hide Mechanism | |
/// @Published var hideTabBar = false | |
/// var tabBarSubscriberCancellable: AnyCancellable? | |
open override func setNeedsDisplay() { | |
super.setNeedsDisplay() | |
// tricky subscribe | |
let coreApp: CoreAppService = ServiceLocator.shared.inject() | |
if coreApp.tabBarSubscriberCancellable == nil { |
OlderNewer