Skip to content

Instantly share code, notes, and snippets.

Avatar

はるふ ha1f

View GitHub Profile
View RotatableImageView.swift
/// 中心に画像を描画する
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 Dec 13, 2017
QR Code Generator
View QrCodeGenerator.swift
//
// QrCodeGenerator.swift
// CoreImageSample
//
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
//
import Foundation
import CoreImage
View PrintingViewController.swift
class PrintingViewController: UIViewController {
// Load
override func loadView() {
super.loadView()
print("lifecycle", #function)
}
override func viewDidLoad() {
View String+Extension.swift
import Foundation
extension UnicodeScalar {
/// `a-z{
var isLowerCase: Bool {
return value >= 0x61 && value <= 0x7a
}
/// @A-Z[
var isUpperCase: Bool {
View UIViewSafeAreaLayoutGuide+Extension-3.swift
//
// SafeAreaLayoutGuideCompatible.swift
//
// Created by はるふ on 2017/12/21.
// Copyright © 2017年 ha1f. All rights reserved.
//
import UIKit
View UIViewSafeAreaLayoutGuide+Extension.swift
// 案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
An Observable emits item only if _current == timeToLucky. Useful for testing.
View NthTimeLucky.swift
//
// NthTimeLucky.swift
//
// Created by はるふ on 2018/05/24.
// Copyright © 2018年 ha1f. All rights reserved.
//
import Foundation
import RxSwift
View UIImageTransformer.swift
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:
View kojiharu.swift
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)
View History.swift
class History<T> {
// MARK: Properties
private var _undoStack: [T] = []
private var _redoStack: [T] = []
private var _current: T
// MARK: Getter, Setter