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
/// 指定した桁数で2進数を表示する、0埋め | |
func formatBinary8(_ num: UInt8, digits: Int = 8) -> String { | |
let s = String(num, radix: 2) | |
return s.count < digits | |
? String(repeating: "0", count: digits - s.count) + s | |
: s | |
} |
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
// | |
// Created by はるふ on 2017/12/11. | |
// Copyright © 2017年 ha1f. All rights reserved. | |
// | |
import Foundation | |
import CoreImage | |
import AVFoundation | |
extension CIFilter { |
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
/// パスから末尾の拡張子を取得する | |
function getFileExtension(path) { | |
let splitted= url.split("."); | |
return splitted[splitted.length - 1]; | |
} | |
/// Google Driveのルート直下の指定の名前の | |
/// フォルダを作成または取得する | |
function getTargetFolder(folderName) { | |
let rootFolder = DriveApp.getRootFolder(); |
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 | |
public protocol EmptyInitializable { | |
init() | |
} | |
extension Int: EmptyInitializable {} | |
extension String: EmptyInitializable {} | |
extension Array: EmptyInitializable {} | |
extension Bool: EmptyInitializable {} |
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 | |
final class WeakObject<T: AnyObject> { | |
weak var _object: T? | |
init(_ object: T) { | |
_object = object | |
} | |
} |
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
private func _hexString<I: BinaryInteger>(_ value: I) -> String { | |
"0x" + String(value, radix: 16) | |
} | |
extension Character { | |
func hexRepresentation() -> String { | |
unicodeScalars | |
.map { _hexString($0.value) } | |
.joined(separator: ", ") | |
} |
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 AVAsset { | |
private func _generator(size: CGSize) -> AVAssetImageGenerator { | |
let generator = AVAssetImageGenerator(asset: self) | |
generator.maximumSize = size | |
generator.appliesPreferredTrackTransform = true | |
return generator | |
} | |
func extractUIImageAsync(size: CGSize) -> Single<UIImage?> { | |
let generator = _generator(size: size) |
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
public extension KeyedDecodingContainerProtocol { | |
func decode<T: Decodable>(forKey key: Key) throws -> T { | |
try decode(T.self, forKey: key) | |
} | |
func decodeSafe<T: Decodable>(forKey key: Key, defaultValue: T) -> T { | |
(try? decode(T.self, forKey: key)) ?? defaultValue | |
} | |
} |
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
// | |
// UIKit+lerp.swift | |
// ha1f | |
// | |
extension CGRect { | |
/// 線形補間した中間矩形を返す | |
/// - parameter otherRect: 目指す先の矩形 | |
/// - parameter rate: 0-1の間の値。0なら自分と、1ならotherRectと同じ。 | |
func lerp(_ otherRect: CGRect, rate: CGFloat) -> CGRect { |
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 UIKIt | |
class CopyableLabel: UILabel { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
_commonInit() | |
} | |
required init?(coder: NSCoder) { | |
super.init(coder: coder) |
NewerOlder