Skip to content

Instantly share code, notes, and snippets.

View ha1f's full-sized avatar

はるふ ha1f

View GitHub Profile
/// 中心に画像を描画する
class RotatableImageView: UIView {
var image: UIImage? {
didSet {
setNeedsDisplay()
}
}
var angle: CGFloat = 0.0
var scale: CGFloat = 1.0
var translateX: CGFloat = 0.0
@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
class PrintingViewController: UIViewController {
// Load
override func loadView() {
super.loadView()
print("lifecycle", #function)
}
override func viewDidLoad() {
import Foundation
extension UnicodeScalar {
/// `a-z{
var isLowerCase: Bool {
return value >= 0x61 && value <= 0x7a
}
/// @A-Z[
var isUpperCase: Bool {
//
// SafeAreaLayoutGuideCompatible.swift
//
// Created by はるふ on 2017/12/21.
// Copyright © 2017年 ha1f. All rights reserved.
//
import UIKit
// 案1
extension UIView {
/// Returns UILayoutGuide compatible with safeAreaLayoutGuide.
/// `.safeAreaLayoutGuide` is available only iOS 11+, but safeAreaLayoutGuide
/// should be same as layoutguide of UIView under iOS 11.
///
/// - returns safeAreaLayoutGuide or layoutGuide of self
func safeLayoutGuideOrSelfLayoutGuide() -> UILayoutGuide {
if #available(iOS 11.0, *) {
@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
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
// import EthereumKit
// import Play
final class Lets {
private let nyanWallet = Wallet("💰")
private let nyan = Haruna("🐈")
func go(to place: String) {
nyan.move(to: place)
class History<T> {
// MARK: Properties
private var _undoStack: [T] = []
private var _redoStack: [T] = []
private var _current: T
// MARK: Getter, Setter