Skip to content

Instantly share code, notes, and snippets.

View ha1f's full-sized avatar

はるふ ha1f

View GitHub Profile
import Foundation
protocol Alphabet {
func compositeAction()
}
class A {
let aProperty = "A"
}
enum ExpressionError: Error {
case invalidInput
case failedParsingValue
case unknown
}
indirect enum Expression {
case value(Double)
case plus(Expression, Expression)
case minus(Expression, Expression)
extension CGRect {
/// 線形補間した矩形を返す
/// - parameter rate: 変化割合。0 <= rate <= 1の範囲で指定する。
func lerp(to rect: CGRect, rate: CGFloat) -> CGRect {
let lerp = _lerpCurried(rate)
return CGRect(
x: lerp(origin.x, rect.origin.x),
y: lerp(origin.y, rect.origin.y),
width: lerp(width, rect.width),
height: lerp(height, rect.height)
@ha1f
ha1f / Regex.swift
Last active May 5, 2020 18:36
Swiftで正規表現
//
// Regex.swift
// ha1fRegex
//
// Created by はるふ on 2016/09/30.
// Copyright © 2016年 はるふ. All rights reserved.
//
import Foundation
extension UIImage {
/// 文字の画像を生成する。文字は中心に置かれる。
///
/// - parameter text: 文字列
/// - parameter font: フォント
/// - parameter textColor: 文字色
/// - parameter imageSize: 生成する画像のサイズ(スクリーンスケール倍される)
/// - returns: 生成されたテキスト画像
static func fromText(_ text: String, font: UIFont, textColor: UIColor, imageSize: CGSize) -> UIImage {
let attributes: [NSAttributedString.Key: Any] = [
// Disposable
enum Disposables {
static func create() -> Disposable {
NopDisposable()
}
static func create(_ dispose: @escaping () -> Void) -> Disposable {
ClosureDisposable(dispose)
}
}
@ha1f
ha1f / PrintEncodable.swift
Created April 17, 2020 07:35
Print encodable as JSON
private func _jsonSerialization(from encodable: Encodable) throws -> String {
let jsonEncoder = JSONEncoder()
jsonEncoder.outputFormatting = .prettyPrinted
let encodedData = try jsonEncoder.encode(config)
return String(data: encodedData, encoding: .utf8)!
}
func prettyPrint(_ encodable: Encodable) {
do {
print(try _jsonSerialization(from: encodable))
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
{% if catalogs %}
{% set imageAlias %}{{param.imageAliasName|default:"AssetImageTypeAlias"}}{% endset %}
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
#if os(OSX)
import AppKit.NSImage
{{accessModifier}} typealias {{imageAlias}} = NSImage
#elseif os(iOS) || os(tvOS) || os(watchOS)
#!/bin/sh
echo "Running pre-commit..."
# pre-commit自体が最新かどうかをチェック
PRECOMMIT_MASTER_FILE='./script/pre-commit'
if [ -e $PRECOMMIT_MASTER_FILE ]; then
diff -s $PRECOMMIT_MASTER_FILE ./.git/hooks/pre-commit > /dev/null 2>&1
if [ $? -ne 0 ]; then
cp $PRECOMMIT_MASTER_FILE ./.git/hooks/pre-commit
//
// CachableRequest.swift
// LIPS
//
import Foundation
import RxSwift
import RxCocoa
private extension ObservableType {