Skip to content

Instantly share code, notes, and snippets.

View a-voronov's full-sized avatar
👽
Curious

Oleksandr Voronov a-voronov

👽
Curious
View GitHub Profile
@a-voronov
a-voronov / .fileMergeFix
Last active April 15, 2024 10:15
Fixing Xcode FileMerge spamming in terminal when merging swift files
cp /Applications/Xcode.app/Contents/SharedFrameworks/SourceModel.framework/Versions/A/Resources/LanguageSpecifications/Swift.xclangspec /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/Swift.xclangspec
@a-voronov
a-voronov / .remap
Created February 7, 2024 11:00
remap Finnish keyboard to US layout
sudo hidutil property --set '{ "UserKeyMapping": [ { "HIDKeyboardModifierMappingSrc": 0x700000064, "HIDKeyboardModifierMappingDst": 0x700000035 }, { "HIDKeyboardModifierMappingSrc": 0x700000035, "HIDKeyboardModifierMappingDst": 0x7000000E1 } ] }'
@a-voronov
a-voronov / requirements-arm64.txt
Last active August 22, 2021 02:33
OpenCV Courses - Jupyter + Python on Big Sur M1 arm64
appnope==0.1.2
argon2-cffi==20.1.0
attrs==21.2.0
backcall==0.2.0
bleach==4.0.0
certifi==2021.5.30
cffi==1.14.6
cycler==0.10.0
debugpy==1.4.1
decorator==4.4.2
@a-voronov
a-voronov / requirements-x86_64.txt
Last active August 27, 2021 22:14
OpenCV Courses - Jupyter + Python + dlib on Big Sur M1 x86_64
appnope==0.1.2
argon2-cffi==20.1.0
attrs==21.2.0
backcall==0.2.0
bleach==4.0.0
cffi==1.14.6
cycler==0.10.0
debugpy==1.4.1
decorator==5.0.9
defusedxml==0.7.1
@a-voronov
a-voronov / Maybe.swift
Created September 5, 2020 23:44
Optional built with Struct 🤪
/// Example of using static functions and properties to construct an instance of a type
/// for a struct, similar to how enum uses its cases.
/// Let's call it Maybe.
struct Maybe<Wrapped> {
private(set) var value: Wrapped!
var hasValue: Bool {
value != nil
}
@a-voronov
a-voronov / AnyLoadingStatus.swift
Last active August 31, 2020 11:08
Loading Status FSM 🚥
/// Represents loading status, consisting of multiple steps.
/// All values' types can be specified depending on the problem.
enum AnyLoadingStatus<Loading, Loaded, Failed, Error: Swift.Error> {
case idle
case loading(Loading)
case loaded(Loaded)
case failed(Failed, Error)
}
extension AnyLoadingStatus {
@a-voronov
a-voronov / GeoHash.swift
Last active September 15, 2021 16:58
proximity-hash
import CoreLocation
/// Geohash algorithm implementation.
///
/// It is a hierarchical spatial data structure which subdivides space into buckets of grid shape,
/// which is one of the many applications of what is known as a Z-order curve, and generally space-filling curves.
///
/// Geohashes offer properties like arbitrary precision
/// and the possibility of gradually removing characters from the end of the code to reduce its size (and gradually lose precision).
/// Geohashing guarantees that the longer a shared prefix between two geohashes is, the spatially closer they are together.
@a-voronov
a-voronov / one-or-more.swift
Last active November 8, 2019 00:39
Lightweight Data-Structure for Storing One or More Elements 🍃
public indirect enum OneOrMore<T> {
case one(T)
case more(T, Self)
}
// MARK: Creation simplified
public extension OneOrMore {
static func few(_ head: T, _ tail: T...) -> OneOrMore {
few(head, tail)
@a-voronov
a-voronov / phantom-fsm.swift
Last active October 12, 2019 20:06
Type-Safe FSM with Phantom Types 👻
// inspired by https://blog.jle.im/entry/introduction-to-singletons-1.html
protocol DoorState {}
enum Opened: DoorState {}
enum Closed: DoorState {}
enum Locked: DoorState {}
struct Door<State: DoorState> {
let id: Int
}
@a-voronov
a-voronov / exponential-backoff.swift
Last active February 27, 2020 05:53
Exponential Backoff Iterator + Retry SignalProducer
struct ExponentialBackoffConfig {
let initialRetries: Int
let initialInterval: TimeInterval
let maxInterval: TimeInterval
let factor: TimeInterval
init(initialRetries: Int = 2, initialInterval: TimeInterval = 0.3, maxInterval: TimeInterval = 120, factor: TimeInterval = 1.6) {
precondition(initialRetries >= 0 && initialInterval >= 0 && maxInterval >= initialInterval && factor > 1)
self.initialRetries = initialRetries