Skip to content

Instantly share code, notes, and snippets.

View simonbs's full-sized avatar
🐼

Simon B. Støvring simonbs

🐼
View GitHub Profile
@simonbs
simonbs / Proxy.swift
Created November 4, 2023 19:09
Property wrapper for proxying values.
@propertyWrapper
struct Proxy<EnclosingType, Value> {
typealias ValueKeyPath = ReferenceWritableKeyPath<EnclosingType, Value>
typealias SelfKeyPath = ReferenceWritableKeyPath<EnclosingType, Self>
static subscript(
_enclosingInstance instance: EnclosingType,
wrapped wrappedKeyPath: ValueKeyPath,
storage storageKeyPath: SelfKeyPath
) -> Value {
@simonbs
simonbs / docc.sh
Last active May 2, 2023 08:04
Generates documentation with Apple's DocC for a target that supports both iOS and macOS.
#!/bin/bash
#######################################################################
# Generates documentation for a target, for example a Swift package,
# that supports both iOS and macOS.
#
# The script is designed to be placed in the root of a Swift package.
# Change the paths as needed if your project structure is different.
#
# In order for DocC to annotate all symbols with the platforms
@simonbs
simonbs / README.md
Last active March 15, 2023 22:21
Installing a specific version with Homebrew

Installing a specific version with Homebrew

The Internet has documented several ways of installing a specific version of a piece of software using Homebrew. None of them seem to work anymore. It seems like a feature that the developers of Homebrew do not want to support fully or at all.

A way of installing a specific version is by executing the following commands. The following assumes that we want to install version 3.24.0 of a package named foo.

Start by creating a new tap. The tap can contain multiple formula so we name it something generic.

@simonbs
simonbs / AppKitTextView.swift
Created January 27, 2023 08:39
Shows how a multi-platform SwiftUI can bridge to UIKit and AppKit.
// Implementation of the view using AppKit.
#if os(macOS)
import AppKit
import SwiftUI
final class AppKitTextView: NSView {
let textView: NSTextView = {
let this = NSTextView()
this.translatesAutoresizingMaskIntoConstraints = false
return this
@simonbs
simonbs / XcodeReleases.js
Last active November 14, 2022 01:50
Sample app that lets you browse Xcode releases. Depends on ScriptUI, my yet-to-be-releases project for building native SwiftUI interfaces in JavaScript.
UI.view = RootView()
function RootView() {
const [isLoading, setLoading] = createSignal(true)
const [xcodeGroups, setXcodeGroups] = createSignal([])
fetchXcodes().then((xcodes) => {
setLoading(false)
setXcodeGroups(groupXcodes(xcodes))
})
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// always-run-in-app: true; icon-color: red;
// icon-glyph: film; share-sheet-inputs: url, plain-text;
// Manages a watchlist of movies. Run the script from the share sheet in the IMDb app to add a movie to the watchlist.
// When a movie is added, you can press the "✅"-button to mark the movie as watched. Press the "👀"-button to mark the button to be watched.
// The watchlist is backed by a JSON file stored in iCloud Drive.
let txts = args.plainTexts
let urls = args.urls
// If a plain text and URL input, we're adding a mocke to the list.
@simonbs
simonbs / Cycling Classifications.js
Created July 2, 2022 09:31
Shows rankings for Tour de France 2022.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: yellow; icon-glyph: bicycle;
let results = await loadResults()
if (config.runsInWidget) {
if (config.widgetFamily == "large") {
let widget = createWidget(results, 8)
await widget.presentLarge()
} else if (config.widgetFamily == "medium") {
let widget = createWidget(results, 3)
@simonbs
simonbs / WWDC22.js
Created May 30, 2022 08:09
Scriptable widget counting down to WWDC22
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: cyan; icon-glyph: apple-alt;
const TITLE = "WWDC22"
const PAST_EVENT_TEXT = "Have a great Dub Dub!"
const DATE = "2022-06-06T17:00:00Z"
const BG_IMG_URL = "https://i.ibb.co/9t9CbxX/wwdc22.png"
const LINK = "https://developer.apple.com/wwdc22/"
let widget = await createWidget()
@simonbs
simonbs / Example.swift
Created April 5, 2022 19:14
Present a portrait-only UIViewController wrapped in UIViewControllerRepresentable from a SwiftUI view.
/**
* This file shows how we can tie all of the above together.
*/
import SwiftUI
// This view can have any orientation-
struct SettingsView: View {
@State private var isPortraitOnlyViewPresented = false
@simonbs
simonbs / GitHub Sponsors Widget.js
Created January 31, 2022 15:19
Shows the total number of GitHub sponsors and the latest sponsors in a widget using the Scriptable app
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: brown; icon-glyph: hand-holding-usd;
// To use this script, you must create a personal access token on GitHub with the `read:org// scope.
// Follow the instructions on the link below to create your personal access token.
//
// https://github.com/settings/tokens
//
// Run the script when you ahve created your personal access token. It'll prompt you to enter the token and store it securely in the keychain on the device.