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 / NSLogger.podspec.json
Created November 10, 2016 15:16
NSLogger master podspec
{
"name": "NSLogger",
"version": "1.7.1",
"license": "BSD",
"summary": "A modern, flexible logging tool.",
"homepage": "https://github.com/fpillet/NSLogger",
"authors": {
"Florent Pillet": "fpillet@gmail.com"
},
"source": {
let swap = Tape Nil EnterLoop ( Cons MoveRight -- →
$ Cons EnterLoop -- [
$ Cons Decrement -- -
$ Cons MoveRight -- →
$ Cons Increment -- +
$ Cons MoveLeft -- ←
$ Cons ExitLoop -- ]
$ Cons MoveLeft -- ←
$ Cons EnterLoop -- [
$ Cons Decrement -- -
@a-voronov
a-voronov / map-covariant-generics.swift
Last active January 12, 2017 02:02
Since Swift doesn't support covariant Generics yet, the only workaround I see so far is to map value via creating new one through map or flatMap 😿
enum Generic<T> {
case Some(T)
init(_ x: T) {
self = .Some(x)
}
func flatMap<U>(@noescape f: (T) throws -> Generic<U>) rethrows -> Generic<U> {
switch self {
case .Some(let x):
@a-voronov
a-voronov / RemoveChildViewController.swift
Created May 15, 2017 23:29
Causing recursive method call by creating method named removeChildViewController (probably conflicting with private api 🤔)
extensions UIViewController
func removeChildViewController(childViewController: UIViewController) {
childViewController.willMoveToParentViewController(nil)
childViewController.view.removeFromSuperview()
childViewController.removeFromParentViewController()
}
}
@a-voronov
a-voronov / ApiService.swift
Last active May 28, 2017 22:42
Lightweight Networking Abstraction Layer
import Foundation
// MARK: - Commons Level
protocol Cancellable {
func cancel()
}
enum Result<T, E: Error> {
case success(T)
@a-voronov
a-voronov / states-by-countries.js
Last active July 23, 2017 17:17
Countries and their subdivisions based on ISO 3166-1:2013
// countries, states and subdivisions were generated relying on next documents:
// http://www.iso.org/iso/country_names_and_code_elements
// http://www.unece.org/cefact/locode/welcome.html
var countriesAndStates = [
{"Country":"AD","State":"Canillo"},
{"Country":"AD","State":"Encamp"},
{"Country":"AD","State":"La Massana"},
{"Country":"AD","State":"Ordino"},
{"Country":"AD","State":"Sant Julià de Lòria"},
@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
@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 / 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)