This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/// Debouncer is useful for situations like following. | |
/// If we want to execute action n sec after the last trigger. | |
public final class Debouncer<T> { | |
let dispatchQueue: DispatchQueue | |
let interval: TimeInterval | |
let action: (T) -> Void | |
private var _lastDispatchTime: DispatchTime? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// import EthereumKit | |
// import Play | |
final class Lets { | |
private let nyanWallet = Wallet("💰") | |
private let nyan = Haruna("🐈") | |
func go(to place: String) { | |
nyan.move(to: place) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
/// CGAffineTransform to apply orientation of the image | |
var orientationTransformer: CGAffineTransform { | |
var transform = CGAffineTransform(translationX: size.width / 2, y: size.height / 2) | |
switch imageOrientation { | |
case .up, .upMirrored: | |
break | |
case .down, .downMirrored: | |
transform = transform.rotated(by: CGFloat.pi) | |
case .left, .leftMirrored: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Array { | |
/// Returns unique pairs from array | |
/// Following is result of `[1, 2, 3, 4].pairs()` | |
/// [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)] | |
func pairs() -> [(Element, Element)] { | |
return enumerated() | |
.flatMap { index, element in | |
dropFirst(index.advanced(by: 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Zip3Sequence.swift | |
// | |
// Created by はるふ on 2018/05/28. | |
// Copyright © 2018年 ha1f. All rights reserved. | |
// | |
import Foundation | |
/// An iterator for `Zip3Sequence`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NthTimeLucky.swift | |
// | |
// Created by はるふ on 2018/05/24. | |
// Copyright © 2018年 ha1f. All rights reserved. | |
// | |
import Foundation | |
import RxSwift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum ExpressionError: Error { | |
case invalidInput | |
case failedParsingValue | |
case unknown | |
} | |
indirect enum Expression { | |
case value(Double) | |
case plus(Expression, Expression) | |
case minus(Expression, Expression) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension UnicodeScalar { | |
/// `a-z{ | |
var isLowerCase: Bool { | |
return value >= 0x61 && value <= 0x7a | |
} | |
/// @A-Z[ | |
var isUpperCase: Bool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PrintingViewController: UIViewController { | |
// Load | |
override func loadView() { | |
super.loadView() | |
print("lifecycle", #function) | |
} | |
override func viewDidLoad() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// QrCodeGenerator.swift | |
// CoreImageSample | |
// | |
// Created by はるふ on 2017/12/11. | |
// Copyright © 2017年 ha1f. All rights reserved. | |
// | |
import Foundation | |
import CoreImage |