Skip to content

Instantly share code, notes, and snippets.

View finestructure's full-sized avatar

Sven A. Schmidt finestructure

View GitHub Profile
#!/bin/sh
set -euo pipefail
# Set the paths to your Old/New Xcodes
OLD_XCODE="/Applications/Xcode-14.3.1.app"
NEW_XCODE="/Applications/Xcode-15.0.0.app" # To get build number
# Get New Xcode build number
OLD_XCODE_BUILD=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${OLD_XCODE}/Contents/Info.plist)
@finestructure
finestructure / async-defer.swift
Last active August 5, 2024 01:34
Async defer
@discardableResult
func run<T>(_ operation: () async throws -> T,
defer deferredOperation: () async throws -> Void) async throws -> T {
do {
let result = try await operation()
try await deferredOperation()
return result
} catch {
try await deferredOperation()
throw error
@finestructure
finestructure / Charting.swift
Last active October 23, 2023 20:22
Swift playground example to create charts with a PDF export button
import SwiftUI
import Charts
import PlaygroundSupport
let spiData: [(package: String, fileCount: Int, mbSize: Int)] = [
(package: "swift-markdown-ui", fileCount: 3796, mbSize: 44),
(package: "Microya", fileCount: 414, mbSize: 4),
(package: "swift-url-routing", fileCount: 9430, mbSize: 101),
@finestructure
finestructure / elf_async_await_test.swift
Created January 28, 2023 12:25
ELF vs async/await behaviour test program
import Foundation
import NIO
extension Array where Element == EventLoopFuture<Void> {
/// Converts a collection of `EventLoopFuture<Void>`s to an `EventLoopFuture<Void>`.
///
/// Acts as a helper for the `EventLoop.flatten(_:[EventLoopFuture<Value>])` method.
///
/// let futures = [el.future(1), el.future(2), el.future(3), el.future(4)]
enum Barcode {
case upc(Int, Int, Int, Int)
case qrCode(String)
}
var productBarcode = Barcode.upc(8, 85909, 51226, 3)
productBarcode = .qrCode("ABCDEFGHIJKLMNOP")
switch productBarcode {
@finestructure
finestructure / compare.swift
Created February 23, 2021 11:00
NSImage diff speed test
import Cocoa
func context(for cgImage: CGImage) -> CGContext? {
guard
let space = cgImage.colorSpace,
let context = CGContext(
data: nil,
width: cgImage.width,
height: cgImage.height,
bitsPerComponent: cgImage.bitsPerComponent,
clean:
@# just delete specific directories instead of .builds so we don't
@# have to re-fetch dependencies
@rm -f .build/debug
@rm -rf .build/x86_64-apple-macosx/
@rm -rf .build/x86_64-unknown-linux/
@rm -rf .build/x86_64-unknown-linux-gnu/
macos-spm-4.2: clean
@echo
// See: https://www.swiftbysundell.com/tips/inline-wrapping-of-uikit-or-appkit-views-within-swiftui/
import SwiftUI
#if os(iOS)
public struct Wrap<Wrapped: UIView>: UIViewRepresentable {
public typealias Updater = (Wrapped, Context) -> Void
var makeView: () -> Wrapped
@finestructure
finestructure / test_run.swift
Created April 9, 2020 15:27
Test for adapting a progress handler to Effect.subject
import Combine
import ComposableArchitecture
import ComposableArchitectureTestSupport
import XCTest
class MainViewTests: XCTestCase {
func test_run() throws {
// Setup
struct State: Equatable {
var busy = false
@finestructure
finestructure / CAProtocols.swift
Last active April 14, 2020 07:58
"Guidance protocols" for Composable Architecture
//
// CAProtocols.swift
// RequirementEditor
//
// Created by Sven A. Schmidt on 29/03/2020.
// Copyright © 2020 finestructure. All rights reserved.
//
import SwiftUI