Skip to content

Instantly share code, notes, and snippets.

View helje5's full-sized avatar

Helge Heß helje5

View GitHub Profile
@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) {
@helje5
helje5 / TestView.swift
Created November 27, 2018 09:45
Nested NSStackViews lead to ambiguous layout
import Cocoa
final class TestView : NSView {
static func makeAndAttachToView(_ rootView: NSView) {
let view = TestView()
view.translatesAutoresizingMaskIntoConstraints = false
rootView.addSubview(view)
NSLayoutConstraint.activate([
@helje5
helje5 / InPlaceEnumEditing.swift
Created April 7, 2018 11:20
In-place editing of associated values in enums
struct MyArray<Element> : CustomStringConvertible {
class Storage<T> {
var values = ContiguousArray<T>()
}
var storage = Storage<Element>()
init<T: Sequence>(contentsOf s: T) where T.Element == Element {
for item in s { storage.values.append(item) }
@helje5
helje5 / GenericDowncast.swift
Last active February 11, 2018 10:20
Swift Generic Downcast Question
protocol BaseProtocol {
func doIt()
}
protocol DerivedProtocol : BaseProtocol {
func hello()
}
class MyObject: DerivedProtocol {
func doIt() { print("doIt") }
func hello() { print("hello") }
@helje5
helje5 / KeyPathMirror.swift
Created January 28, 2018 17:16
Swift Key Path Memory Layout Decoding
import Foundation
// https://github.com/apple/swift/blob/master/docs/ABI/KeyPaths.md
// https://bugs.swift.org/browse/SR-5689
public struct KeyPathMirror<T: AnyKeyPath> : CustomStringConvertible {
public let subject : T
//
// main.swift
// TestRecursiveNSArchive
//
// Created by Helge Hess on 09.12.17.
// Copyright © 2017 ZeeZide GmbH. All rights reserved.
//
import Foundation