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 / 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 / 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 / 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 / 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 / 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 / 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 / state-machine.swift
Last active July 10, 2018 17:48
State Machine
// MARK: - Read-Write Queue
class ReadWriteQueue {
private let specificKey = DispatchSpecificKey<String>()
private let queue: DispatchQueue
private var isAlreadyInQueue: Bool {
return DispatchQueue.getSpecific(key: specificKey) == queue.label
}
@a-voronov
a-voronov / read-write-queue.swift
Last active July 13, 2018 15:25
Concurrent Reads, Blocking Write
class ReadWriteQueue {
private let specificKey = DispatchSpecificKey<String>()
private let queue: DispatchQueue
private var isAlreadyInQueue: Bool {
return DispatchQueue.getSpecific(key: specificKey) == queue.label
}
init(label: String = "read-write.queue") {
queue = DispatchQueue(label: label, attributes: .concurrent)
@a-voronov
a-voronov / data-type.swift
Created May 15, 2018 19:24
What's the name for this data type or approach?
enum S {
case a, b
}
struct MapOfS<T> {
private var a: T, b: T
subscript(_ s: S) -> T {
get {
switch s {
@a-voronov
a-voronov / ski-combinators.swift
Created September 6, 2017 23:34
SKI Combinators in Swift 3
func s<A, B, C>(_ f: @escaping (A) -> (B) -> C) -> (@escaping (A) -> B) -> (A) -> C {
return { g in { x in f(x)(g(x)) } }
}
func k<A, B>(_ x: A) -> (B) -> A {
return { _ in x }
}
func i<A>(_ x: A) -> A {
return x