Skip to content

Instantly share code, notes, and snippets.

View helje5's full-sized avatar

Helge Heß helje5

View GitHub Profile
@helje5
helje5 / main.swift
Last active January 12, 2022 18:44
Using async/await concurrency on iOS 14 and before
// Created by Helge Heß 2021-06-17
import Foundation
// They use obfuscated names to hide it from us!
import JavaScriptCore
/// Setup our async/await runtime.
let runtime = JSContext()!
@helje5
helje5 / cal.swift
Created February 20, 2022 15:13
A completely incomplete implementation of `cal` using Swift / Foundation.Calendar
#!/usr/bin/swift
import Foundation
extension DateInterval {
func containsOpen(_ date: Date) -> Bool { date >= start && date < end }
}
struct MonthCalendar {
@helje5
helje5 / Tows.swift
Last active June 12, 2022 06:33
An 82-liner SwiftUI script similar to CodeCows 🐮
import SwiftUI
import cows // @AlwaysRightInstitute
struct ContentView: View {
@State var searchString = ""
@State var matches = allCows
@State var selectedCow : String?
let font = Font(NSFont
@helje5
helje5 / servedocc.swift
Last active July 16, 2022 22:24
Small Swift Script to serve `.doccarchive`s to the browser
#!/usr/bin/swift sh
import MacroExpress // @Macro-swift
// MARK: - Parse Commandline Arguments & Usage
func usage() {
let tool = path.basename(process.argv.first ?? "servedocc")
print(
"""
@helje5
helje5 / SparkleCommands.swift
Last active January 11, 2023 00:37
How to hookup Sparkle in SwiftUI
//
// SparkleCommands.swift
// Past for iChat
//
// Created by Helge Heß on 08.04.21.
//
import SwiftUI
#if SPARKLE && canImport(Sparkle)
@helje5
helje5 / RepeatedModelInits.swift
Last active September 16, 2023 11:34
Repeated Model Inits w/ State
import SwiftUI
@Observable class Tester {
init() { print("INIT:", ObjectIdentifier(self)) }
deinit { print("DEINIT:", ObjectIdentifier(self)) }
}
struct ContentView: View {
struct Nested: View {
@helje5
helje5 / StateObservable.swift
Created September 16, 2023 13:16
An `Observable` property wrapper that only creates the observable value once
/**
* An Observable property wrapper that only creates the observable
* value once.
*
* Example:
* ```swift
* @Observable class Item {
* }
*
* struct MyView: View {
@helje5
helje5 / SwiftData Inverse Relationships.swift
Created September 13, 2023 21:36
SwiftData Inverse Relationships
import SwiftUI
import SwiftData
@Model final class Address {
let street = "Am Geldspeicher 1"
var contact : Contact?
init() {}
}
@Model final class Contact {
@helje5
helje5 / SVGWebView.swift
Created May 10, 2021 12:54
A SwiftUI View to display SVGs using WKWebView
// Created by Helge Heß on 06.04.21.
// Also available as a package: https://github.com/ZeeZide/SVGWebView
import SwiftUI
import WebKit
/**
* Display an SVG using a `WKWebView`.
*
* Used by [SVG Shaper for SwiftUI](https://zeezide.de/en/products/svgshaper/)
@helje5
helje5 / ListCellSizingFlicker.swift
Last active October 16, 2023 21:30
ListCellSizingFlicker
import SwiftUI
struct Item: Identifiable {
let id = UUID()
let title = "Hello"
}
let items = [
Item(), Item(), Item(), Item(), Item(), Item(), Item(), Item(), Item(), Item(), Item(),
Item(), Item(), Item(), Item(), Item(), Item(), Item(),