Skip to content

Instantly share code, notes, and snippets.

View ollieatkinson's full-sized avatar
👋

Oliver Atkinson ollieatkinson

👋
View GitHub Profile
@ollieatkinson
ollieatkinson / LWin_to_F13.reg
Last active December 30, 2025 21:07
AHK layout for Keychron Q6 HE for Mac layout on Windows
Windows Registry Editor Version 5.00
; Map Left Windows key (E0 5B) to F13 (0064)
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,64,00,5b,e0,00,00,00,00
@ollieatkinson
ollieatkinson / Tuple.swift
Last active November 19, 2025 03:55
Implementation of `Tuple` type using Swift's new parameter packs
public struct Tuple<each T> {
public private(set) var value: (repeat each T)
public init(_ value: repeat each T) { self.value = (repeat each value) }
}
extension Tuple {
public func map<each U>(
_ transform: (repeat each T) throws -> (repeat each U)
) rethrows -> (repeat each U) {
@ollieatkinson
ollieatkinson / SVG.swift
Last active October 29, 2025 11:52
Utilise the private CoreSVG framework in Swift
import Darwin
import Foundation
import UIKit
// https://github.com/xybp888/iOS-SDKs/blob/master/iPhoneOS17.1.sdk/System/Library/PrivateFrameworks/CoreSVG.framework/CoreSVG.tbd
// https://developer.limneos.net/index.php?ios=17.1&framework=UIKitCore.framework&header=UIImage.h
@objc
class CGSVGDocument: NSObject { }
@ollieatkinson
ollieatkinson / HTTPStatusCode.swift
Last active April 12, 2025 22:44
HTTP status codes as a Swift enum.
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational
@ollieatkinson
ollieatkinson / Publishers+RetryDelay.swift
Last active January 31, 2025 11:28
Add a delay in-between each Combine retry, offering a timing function and default implementations for none, constant seconds and exponential backoff
import Combine
import Foundation
extension Publisher {
public func retry<S: Scheduler>(
_ max: Int = Int.max,
delay: Publishers.RetryDelay<Self, S>.TimingFunction,
scheduler: S
) -> Publishers.RetryDelay<Self, S> {
@ollieatkinson
ollieatkinson / Result+SharedStore.swift
Last active August 16, 2024 11:11
A store type with support for sharing, caching, invalidating and streaming `Result` values from `source`
extension Result where Success: Sendable, Failure == Error {
actor SharedStore {
typealias ID = UInt
private let source: AsyncStream<Result>
private let cancellingGracePeriod: Duration
private let clock: ContinuousClock
@ollieatkinson
ollieatkinson / Restorable.swift
Created June 16, 2020 08:43
Restorable - Undo/Redo management of values using Swift 5.1 property wrappers
@propertyWrapper
public struct Restorable<Value> {
public var wrappedValue: Value
public init(wrappedValue: Value, using undoManager: UndoManager = .init()) {
self.wrappedValue = wrappedValue
self.projectedValue = undoManager
}
@ollieatkinson
ollieatkinson / URLDecoder.swift
Created May 22, 2024 20:16
Decoder for decoding URL into a concrete type
import Foundation
public final class URLDecoder: Decoder {
public var codingPath: [CodingKey] = []
public var userInfo: [CodingUserInfoKey: Any] = [:]
let parseParametersFromURL: (URL) throws -> [String: Any]
public init<Output>(_ regex: Regex<Output>) {
self.parseParametersFromURL = { url in
@ollieatkinson
ollieatkinson / OnChangeObservable.swift
Last active May 15, 2024 06:08
OnChangeObservable property wrapper
@propertyWrapper
public struct OnChangeObservable<Value: Equatable> {
private var storage: Storage
public var wrappedValue: Value {
get { storage.value }
set { storage.value = newValue }
}
public var projectedValue: OnChangeObservable<Value> {
@ollieatkinson
ollieatkinson / JSONObject.swift
Last active April 8, 2024 21:41
JSON Equatable in Swift
public let null = NSNull() as AnyHashable
public enum JSONObject {
case array([Any])
case dictionary([String: Any])
case fragment(Any)
}
extension JSONObject {
@inlinable public static func with(_ data: Data, options: JSONSerialization.ReadingOptions = []) throws -> JSONObject {