Skip to content

Instantly share code, notes, and snippets.

View helje5's full-sized avatar

Helge Heß helje5

View GitHub Profile
@helje5
helje5 / CompareAnySwift57.swift
Created August 2, 2023 16:20
Compare Any w/ Swift 5.7
func isEqual(_ lhs: Any, _ rhs: Any) -> Bool {
guard let lhs = lhs as? any Equatable else { return false }
func isEqual<T: Equatable>(lhs: T, rhs: Any) -> Bool {
guard let rhs = rhs as? T else { return false }
return lhs == rhs
}
return isEqual(lhs: lhs, rhs: rhs)
}
@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 / 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 / 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 / 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 / CliptIt.swift
Created July 17, 2020 15:55
Demo for SwiftBlocksUI: Clip Slack messages using a Message Action
#!/usr/bin/swift sh
import SwiftBlocksUI // @SwiftBlocksUI ~> 0.8.0
dotenv.config()
struct ClipItForm: Blocks {
@State(\.messageText) var messageText
@State var importance = "medium"
@helje5
helje5 / SlashCows.swift
Created July 17, 2020 15:52
ASCII Cows for Slack, as a Slash Command - a SwiftBlocksUI demo
#!/usr/bin/swift sh
import cows // @AlwaysRightInstitute ~> 1.0.0
import SwiftBlocksUI // @SwiftBlocksUI ~> 0.8.0
dotenv.config()
struct CowMessage: Blocks {
@Environment(\.messageText) private var query
@helje5
helje5 / AppDelegate.swift
Last active March 22, 2019 14:10
Dock gets stuck on drag
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window : NSWindow!
@IBOutlet weak var tableView : NSTableView!
func applicationDidFinishLaunching(_ aNotification: Notification) {