This file contains hidden or 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
enum APCA { | |
static func gamma(for channel: CGFloat) -> Double { | |
pow(channel, 2.4) | |
} | |
static func luminance(for color: RGBColor) -> Double { | |
let r = gamma(for: color.red) | |
let g = gamma(for: color.green) | |
let b = gamma(for: color.blue) | |
var y = 0.2126729 * r + 0.7151522 * g + 0.0721750 * b |
This file contains hidden or 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
// Naive port of https://github.com/Myndex/apca-w3/blob/master/src/apca-w3.js | |
import Foundation | |
enum SA98G { | |
static let mainTRC = 2.4 // 2.4 exponent for emulating actual monitor perception | |
// For reverseAPCA | |
static func mainTRCencode() -> Double { return 1 / mainTRC } |
This file contains hidden or 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
func truesFirst<T>(_ propertyAccessor: @escaping (T) -> Bool) -> (T, T) -> Bool { | |
{ lhs, rhs in | |
propertyAccessor(lhs) && !propertyAccessor(rhs) | |
} | |
} | |
func falsesFirst<T>(_ propertyAccessor: @escaping (T) -> Bool) -> (T, T) -> Bool { | |
{ lhs, rhs in | |
!propertyAccessor(lhs) && propertyAccessor(rhs) | |
} |
This file contains hidden or 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
struct PaginationModifier: ViewModifier { | |
let metadata: PaginationMetadata? | |
let onBottom: () -> Void | |
func body(content: Content) -> some View { | |
content | |
if let metadata, !metadata.isAtEnd, metadata.items != 0 { | |
VStack { | |
Text("Page \(metadata.page) of \(metadata.pages).") | |
Text("\(metadata.items) total items.") |
This file contains hidden or 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 AsyncHTTPClient | |
import Foundation | |
struct ServerSentEvent { | |
let name: String | |
let data: String | |
init(_ substring: Substring) { | |
let lines = substring.split(whereSeparator: \.isNewline) | |
self.name = String(lines |
This file contains hidden or 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
// | |
// ContentView.swift | |
// DependentEnvironment | |
// | |
// Created by Soroush Khanlou on 3/27/23. | |
// | |
import SwiftUI | |
struct Inner: View { |
This file contains hidden or 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
struct BundleVersion: Comparable { | |
let tuple: (Int, Int, Int) | |
init(string: String) { | |
let numbers = string.split(separator: ".").compactMap({ Int($0) }) | |
let major = numbers.count >= 1 ? numbers[0] : 0 | |
let minor = numbers.count >= 2 ? numbers[1] : 0 | |
let patch = numbers.count >= 3 ? numbers[2] : 0 |
This file contains hidden or 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 SwiftUI | |
struct IdentifiableError: Identifiable { | |
let error: Error | |
var id: String { | |
let nsError = error as NSError | |
return "\(nsError.domain) \(nsError.code)" | |
} |
This file contains hidden or 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 CanCan<Identity, Action: Equatable> { | |
var registry: [(String, (Identity, Any) -> [Action])] = [] | |
mutating func register<T>(_ type: T.Type, _ block: @escaping (Identity, T) -> [Action]) { | |
self.registry.append((String(describing: type), { (identity: Identity, object: Any) -> [Action] in | |
guard let casted = object as? T else { | |
return [] |
NewerOlder