Skip to content

Instantly share code, notes, and snippets.

View finestructure's full-sized avatar

Sven A. Schmidt finestructure

View GitHub Profile
@finestructure
finestructure / list-toolchains.swift
Last active March 26, 2024 10:39
List Swift toolchain IDs
#!/usr/bin/env swift
import Foundation
let toolchainsDir = URL(fileURLWithPath: "/Library/Developer/Toolchains")
struct ToolchainInfoPlist: Codable {
var bundleIdentifier: String
var createdDate: Date
var displayName: String
@finestructure
finestructure / Dockerfile
Last active February 3, 2024 09:58
Pkl dockerfile
FROM swift:5.9-slim
RUN apt-get update && apt-get -y install curl fish
ARG PKL_VERSION=0.25.1
RUN curl -L -o /usr/local/bin/pkl https://github.com/apple/pkl/releases/download/${PKL_VERSION}/pkl-linux-aarch64 && chmod +x /usr/local/bin/pkl
# requires Swift runtime libraries, that's why the base image is swift:5.9-slim
ARG PKL_GEN_SWIFT_VERSION=0.2.1
RUN curl -L -o /usr/local/bin/pkl-gen-swift https://github.com/apple/pkl-swift/releases/download/${PKL_GEN_SWIFT_VERSION}/pkl-gen-swift-linux-aarch64.bin && chmod +x /usr/local/bin/pkl-gen-swift
@finestructure
finestructure / ci.yml
Last active December 11, 2023 11:52
Github CI setup
name: CI
on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
@finestructure
finestructure / daws-test hang
Created December 8, 2023 12:16
daws-test hang
```
❯ ./.build/debug/daws server
starting server...
running.
2023-12-08T13:09:21+0100 info WebSocketActors : channel=[IPv6]::1/::1:57175 op=handleWebsocketChannel(_:remoteNodeID:) [WebSocketActors] new client connection
```
```
❯ ./.build/debug/daws client
starting client...
#!/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)
func run(_ operation: () async throws -> Void,
defer deferredOperation: () async throws -> Void) async throws {
do {
try await operation()
try await deferredOperation()
} 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,