Skip to content

Instantly share code, notes, and snippets.

View ha1f's full-sized avatar

はるふ ha1f

View GitHub Profile
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?
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)
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:
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))
@ha1f
ha1f / Zip3Sequence.swift
Last active July 30, 2018 09:09
Implementation of zip3
//
// Zip3Sequence.swift
//
// Created by はるふ on 2018/05/28.
// Copyright © 2018年 ha1f. All rights reserved.
//
import Foundation
/// An iterator for `Zip3Sequence`.
@ha1f
ha1f / NthTimeLucky.swift
Last active May 25, 2018 03:22
An Observable emits item only if _current == timeToLucky. Useful for testing.
//
// NthTimeLucky.swift
//
// Created by はるふ on 2018/05/24.
// Copyright © 2018年 ha1f. All rights reserved.
//
import Foundation
import RxSwift
enum ExpressionError: Error {
case invalidInput
case failedParsingValue
case unknown
}
indirect enum Expression {
case value(Double)
case plus(Expression, Expression)
case minus(Expression, Expression)
import Foundation
extension UnicodeScalar {
/// `a-z{
var isLowerCase: Bool {
return value >= 0x61 && value <= 0x7a
}
/// @A-Z[
var isUpperCase: Bool {
class PrintingViewController: UIViewController {
// Load
override func loadView() {
super.loadView()
print("lifecycle", #function)
}
override func viewDidLoad() {
@ha1f
ha1f / QrCodeGenerator.swift
Last active December 13, 2017 05:08
QR Code Generator
//
// QrCodeGenerator.swift
// CoreImageSample
//
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
//
import Foundation
import CoreImage