Skip to content

Instantly share code, notes, and snippets.

View ctreffs's full-sized avatar
💭
🏊 🚴‍♂️ 🏃

Christian Treffs ctreffs

💭
🏊 🚴‍♂️ 🏃
View GitHub Profile
@ctreffs
ctreffs / MTLARFrameProcessor.swift
Created November 16, 2023 14:08
Processes ARKits' ARFrame->capturedImage CVPixelBuffer according to the documentation into an sRGB image
import CoreImage
import CoreVideo
import ImageIO
import Metal
/// Processes ARKits' ARFrame->capturedImage CVPixelBuffer according to the documentation into an sRGB image.
///
/// ARKit captures pixel buffers in a full-range planar YCbCr format (also known as YUV) format according to the ITU R. 601-4 standard.
/// (You can verify this by checking the kCVImageBufferYCbCrMatrixKey pixel buffer attachment.)
/// Unlike some uses of that standard, ARKit captures full-range color space values, not video-range values.
@ctreffs
ctreffs / resource_bundle_accessor.swift
Created June 2, 2022 08:05
resource_bundle_accessor.swift
import class Foundation.Bundle
private class BundleFinder {}
extension Foundation.Bundle {
/// Returns the resource bundle associated with the current Swift module.
static var module: Bundle = {
let bundleName = "<PACKAGENAME_MODULENAME>"
let candidates = [
protocol State {
var manager: AppUpdateManager { get }
init(manager: AppUpdateManager)
}
protocol UpdateProcessControlling {
func startUpdate()
func postponeUpdate()
}
//
// StateMachine.swift
//
//
// Created by Christian Treffs on 24.06.20.
//
public typealias FSM<State, StateInstance> = StateMachine<State, StateInstance> where State: Equatable
public final class StateMachine<State, StateInstance> where State: Equatable {
/// Current state of this finite-state machine.
@ctreffs
ctreffs / xcappdata.md
Last active September 6, 2023 08:16

Current State of xcappdata

Apple feedback submitted: FB9905889

Up to Xcode version 13 xcappdata container are not behaving as expected: xcappdata container set in xctestplan configurations or via schemes ...

import Foundation
import CoreFoundation
public final class CoreNotificationCenter {
public static let darwin = CoreNotificationCenter(CFNotificationCenterGetDarwinNotifyCenter())
public static let local = CoreNotificationCenter(CFNotificationCenterGetLocalCenter())
#if os(macOS)
public static let distributed = CoreNotificationCenter(CFNotificationCenterGetDistributedCenter())
@ctreffs
ctreffs / KeyPathReflectable.swift
Created November 8, 2021 20:18
KeyPathReflectable
// <https://github.com/tensorflow/swift-apis/blob/main/Sources/TensorFlow/Core/KeyPathIterable.swift>
// <https://github.com/apple/swift/blob/main/stdlib/public/core/ReflectionMirror.swift>
// <https://github.com/tensorflow/swift/blob/main/docs/DynamicPropertyIteration.md>
// <https://forums.swift.org/t/getting-keypaths-to-members-automatically-using-mirror/21207>
// <https://github.com/Azoy/Echo>
public protocol KeyPathReflectable {
func reflect(allKeyPaths keyPaths: inout [PartialKeyPath<Self>])
func reflect(allKeyPaths keyPaths: inout [String: PartialKeyPath<Self>])
@ctreffs
ctreffs / README.md
Created October 28, 2021 10:15 — forked from keith/README.md
A test of `@_dynamicReplacement` in Swift

Usage

  1. swiftc main.swift -emit-module-path main.swiftmodule -emit-executable -enable-private-imports -Xfrontend -enable-implicit-dynamic
  2. ./main -> prints From original bar()
  3. swiftc -emit-library inject.swift -o inject.dylib -I . -Xlinker -undefined -Xlinker suppress -Xlinker -flat_namespace -Xfrontend -disable-access-control
  4. DYLD_INSERT_LIBRARIES=inject.dylib ./main -> prints From replacement bar()

Notes

  • Passing -Xfrontend -enable-implicit-dynamic removes you from having to add dynamic to everything you want to be replacable
@ctreffs
ctreffs / Tuple.swift
Created June 29, 2021 12:51 — forked from beccadax/Tuple.swift
Exploring user-space tuple designs in the quest for variadic generics.
// First, let's test out the basic design. This is basically just an
// HList.
// This recurses to the right because that makes subscripting simpler,
// at the cost of making appending impossible to generalize.
public protocol TupleProtocol: RandomAccessCollection
where Index == Int, IndexDistance == Int, Element == Any
{
associatedtype First
associatedtype Rest //: TupleProtocol
@ctreffs
ctreffs / deployable-artifacts.md
Created June 27, 2021 07:46 — forked from ddunbar/deployable-artifacts.md
Deployable Artifacts thoughts

My hopes for deployable artifacts:

  1. Packages would be able to just describe how the things they build should get laid out in a tarball.
  2. We would implement this as part of the build, it should be super fast (we might want to consider actually generating the tar directly for portability & control purposes).
  3. Packages could have control over the permissions inside the tar file (ideally without having to manipulate the permissions in the filesystem, problematic sometimes if root permission in the tar is desired).
  4. The mechanism would support knowing how to handle RPATH issues.
  5. The mechanism would know how to handle libswift* portability issues.
  6. The mechanism would know how to handle cross-Linux distro issues.
  7. Unlike below, I wouldn't expect the mechanism to handle the GIT REVISION stuff, that belongs in a separate proposal.
  8. The mechanism would support typical Unix-y things, like bin, lib, libexec, share.
  9. The mechanism could support vendored assets like other DSOs or frameworks that can't l