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 / random.stencil
Last active January 29, 2019 17:07
Lightweight Random utils inspired by RandomKit, using seedable Xoroshiro generator from CwlUtils. Sourcery templates included.
import Foundation
{# So far getting imports hardcoded from config, correct approach might be found here: https://github.com/krzysztofzablocki/Sourcery/issues/670 #}
{% for import in argument.imports %}
import {{ import }}
{% endfor %}
{% if argument.testable %}{% for testable in argument.testable %}
@testable import {{ testable }}
{% endfor %}{% endif %}
@a-voronov
a-voronov / Monokai.xccolortheme
Last active October 27, 2023 06:16
Xcode 11 Monokai Theme 🎨
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>1 1 1 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>SFMono-Medium - 12.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>1 1 1 1</string>
@a-voronov
a-voronov / mr-reminder.rb
Last active May 14, 2020 13:09
Gitlab Merge Requests Reminder
require 'getoptlong'
require 'gitlab'
opts = GetoptLong.new(
['--help', '-h', GetoptLong::NO_ARGUMENT],
['--endpoint', '-e', GetoptLong::REQUIRED_ARGUMENT],
['--token', '-t', GetoptLong::REQUIRED_ARGUMENT],
['--group', '-g', GetoptLong::REQUIRED_ARGUMENT],
['--webhook', '-w', GetoptLong::REQUIRED_ARGUMENT]
)
@a-voronov
a-voronov / optics.swift
Created January 27, 2019 22:23
lens + prism + affine
// MARK: - Original material
// Brandon Williams - Lenses in Swift: https://youtu.be/ofjehH9f-CU
// Lenses and Prisms in Swift: a pragmatic approach: https://broomburgo.github.io/fun-ios/post/lenses-and-prisms-in-swift-a-pragmatic-approach/
// Lenses and Prisms in Swift - Elviro Rocca: https://youtu.be/8VhYFEAQ0FY
// Elviro Rocca - Advanced Swift Optics: https://youtu.be/ki2WSw2WXV4
// MARK: - Either
enum Either<Left, Right> {
@a-voronov
a-voronov / async-tasks-serial-queue.swift
Last active March 10, 2022 10:43
Async Task + Serial Queue based on ReactiveSwift ✨
import ReactiveSwift
import Result
// MARK: - Task
final class Task<V, E: Error> {
typealias ProcessingHandler = (@escaping (Result<V, E>) -> Void, DisposableBag) -> Void
enum State {
case idle
@a-voronov
a-voronov / pretty-description.swift
Created May 2, 2019 16:15
Pretty Swift.Any description
func prettyDescription(of subject: Any, indentCoeff: Int = 0) -> String {
let mirror = Mirror(reflecting: subject)
let properties = mirror.children
guard let displayStyle = mirror.displayStyle else {
return String(reflecting: subject)
}
let indent = "\t"
let globalIndent = String(repeating: indent, count: indentCoeff)
@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
@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 / 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 / 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.