Skip to content

Instantly share code, notes, and snippets.

View finestructure's full-sized avatar

Sven A. Schmidt finestructure

View GitHub Profile
@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
// 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
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
@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,
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 / 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)]
@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),
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
}
}
#!/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 / 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...