Skip to content

Instantly share code, notes, and snippets.

View MaximKotliar's full-sized avatar
🚲
Педалю ровери

Maxim Kotliar MaximKotliar

🚲
Педалю ровери
View GitHub Profile
@MaximKotliar
MaximKotliar / DistributedLock.swift
Created March 15, 2024 16:39
Cross-process (distributed) lock.
/// Distributed lock based on file locking
final class DistributedLock: NSLocking {
enum Error: Swift.Error {
case failToAquireLock
}
private let fileURL: URL
private var fileDescriptor: Int32 = -1
import Foundation
public enum SafeCodableEnum<Nested: RawRepresentable & Codable> where Nested.RawValue: Codable {
case defined(Nested)
case other(Nested.RawValue)
}
extension SafeCodableEnum: RawRepresentable {
import UIKit
import SwiftUI
protocol AnyNode: AnyCodableType {
var id: UUID { get }
}
protocol AnyNodeContent: AnyCodableType {}
extension AnyNodeContent {
static func register() {
public final class Stopwatch {
var start: DispatchTime = .now()
let maxTime: TimeInterval
let measurementTitle: String
private var isReportedAtLeastOnce = false
@discardableResult
static func create(title: String = #function, maxTime: TimeInterval = 0) -> Stopwatch {
@MaximKotliar
MaximKotliar / fxaa.metal
Created October 30, 2020 16:37
Metal FXAA anti-aliasing
#include <metal_stdlib>
using namespace metal;
#include <CoreImage/CoreImage.h>
extern "C" {
namespace coreimage {
static float4 textureAtLocation(sampler s, float2 c) {
//
// KeyPathBasedConfiguration.swift
//
// Created by Maxim Kotliar on 13.02.2020.
// Copyright © 2020 Wikrgroup. All rights reserved.
//
import Foundation
@dynamicMemberLookup
import UIKit
import PlaygroundSupport
import CoreGraphics
extension Numeric {
/// Linear interpolation
/// - Parameters:
/// - a: a value to interpolate from
/// - b: a value to interpolate to
/// - delta: interpolation delta value (0 - 1)
//
// UserDefaultsManagedWrapper.swift
// Yoga
//
// Created by Maxim Kotliar on 11.12.2019.
// Copyright © 2019 Wikrgroup. All rights reserved.
//
import Foundation
import Bindy
@MaximKotliar
MaximKotliar / AVPlayerDelegate.swift
Last active November 28, 2022 18:33
A easier way to handle AVPlayer's events
// AVPlayerDelegate.swift
//
// Created by Maxim Kotliar on 7/30/18.
//
import AVFoundation
@objc protocol AVPlayerDelegate: class {
@objc optional func playerDidStartPlayback()
@objc optional func playerDidPausePlayback()
@MaximKotliar
MaximKotliar / DecodeArrayAllowingInvalidElements.swift
Last active July 8, 2018 21:57
Adds ability to decode array allowing invalid elements
extension KeyedDecodingContainer {
struct Safe<Base: Decodable>: Decodable {
public let value: Base?
public init(from decoder: Decoder) throws {
do {
let container = try decoder.singleValueContainer()
self.value = try container.decode(Base.self)
} catch {