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 | |
/// 要素 | |
protocol Element { | |
/// HTMLを書き出すレンダー | |
/// - Returns: HTML | |
func render() -> String | |
} |
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
require 'optparse' | |
inFile = 'base.jpg' | |
outFile = 'glitch.jpg' | |
e = 0.0 | |
ARGV.options do |opt| | |
opt.on('-i [OPTIONAL]') {|v| inFile = v.to_s } | |
opt.on('-o [OPTIONAL]') {|v| outFile = v.to_s } | |
opt.on('-e [OPTIONAL]') {|v| e = v.to_f } |
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 | |
/// 値を範囲内に収める | |
@propertyWrapper struct ClampValue<T> where T: Comparable { | |
private var value: T | |
init(_ range: ClosedRange<T>) { | |
value = range.lowerBound | |
projectedValue = range | |
} |
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 | |
struct Rates: Codable { | |
let quotes: [Rate] | |
struct Rate: Codable { | |
let bid: String | |
let currencyPairCode: String | |
} | |
} |
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 | |
@propertyWrapper struct RotationValue<T> where T: Numeric, T: Comparable { | |
private var value: T | |
private var length: T | |
init(_ range: ClosedRange<T>) { | |
value = range.lowerBound | |
projectedValue = range |
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 | |
extension Array where Element: Hashable { | |
var tally: [Element : Int] { | |
Dictionary(grouping: self) { $0 }.compactMapValues { $0.count } | |
} | |
} | |
let a = ["a", "b", "c", "d", "e", "a", "b", "c", "d", "a", "b", "c", "a", "b", "a"] | |
print(a.tally) |
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 | |
extension Array where Element: Equatable { | |
var unique: [Element] { | |
reduce([Element]()) { $0.contains($1) ? $0 : $0 + [$1] } | |
} | |
} | |
let a = ["a", "b", "c", "d", "e", "a", "b", "c", "d", "a", "b", "c", "a", "b", "a"] | |
print(a.unique) |
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 | |
extension CGPoint { | |
static func *<T: BinaryFloatingPoint>(lhs: CGPoint, rhs: T) -> CGPoint { | |
CGPoint(x: lhs.x * CGFloat(rhs), y: lhs.y * CGFloat(rhs)) | |
} | |
static func *=<T: BinaryFloatingPoint>(left: inout CGPoint, right: T) { | |
left = CGPoint(x: left.x * CGFloat(right), y: left.y * CGFloat(right)) | |
} |
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 | |
extension URLRequest { | |
enum Method: String { | |
case get = "GET" | |
case post = "POST" | |
case put = "PUT" | |
case delete = "DELETE" | |
} | |
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 | |
protocol ConfigBase { | |
associatedtype Key: RawRepresentable, CaseIterable where Key.RawValue == String | |
var userDefaults: UserDefaults { get } | |
func set(_ value: Any?, forKey key: Key) | |
func set(_ value: Float, forKey key: Key) | |
func set(_ value: Double, forKey key: Key) |
OlderNewer