Skip to content

Instantly share code, notes, and snippets.

View Bonney's full-sized avatar

Matt Bonney Bonney

View GitHub Profile
@Bonney
Bonney / SwiftData+Measurement.swift
Created November 29, 2023 14:12
This appears the be the bare-minimum workaround currently needed to use Swift's `Measurement` type in SwiftData.
@Model
final public class Drink {
/// Holds the JSON-encoded data blob representing the Measurement.
private var _measurement: Data?
/// The actual Measurement, encoded/decoded on-the-fly.
@Transient var measurement: Measurement<UnitVolume> {
get { getMeasurement() }
set { setMeasurement(newValue) }
}
@Bonney
Bonney / TicTacToe.swift
Last active May 26, 2023 13:55
Simple tic-tac-toe game in Swift.
import Foundation
enum Marker: String {
case x = "x"
case o = "o"
}
typealias Position = Int
enum ValidPositions {
@Bonney
Bonney / Win95Key.swift
Created February 27, 2023 22:13
Generating Windows 95 OEM product keys, using Swift, for the heck of it.
// Inspired by this Hacker News comment:
// https://news.ycombinator.com/item?id=34954579
//
// OEM Windows 95 keys came in the form of XXXXX-OEM-00YYYYY-ZZZZZ. The XXXXX grouping represents when Microsoft issued the key by day-of-year and year, and the operating system would validate any number where the first three numbers range from 001 to 365 (or 366 for year 96), and the last two X digits were 95-99. The YYYYY group must be a multiple to 7, excluding the number 0. The ZZZZZ group is basically noise and anything is permissible in them.
//
// Now you can run a Windows 95 keygen in your head. You're welcome :)
//
import Foundation
import Swift
@Bonney
Bonney / NotesApp.swift
Created November 10, 2020 14:30 — forked from jnewc/NotesApp.swift
A notes app written in >100 lines of swift using SwiftUI
//
// ContentView.swift
// Listomania
//
// Created by Jack Newcombe on 05/06/2019.
// Copyright © 2019 Jack Newcombe. All rights reserved.
//
import SwiftUI
@Bonney
Bonney / setAlternateIconWithoutAlert.swift
Last active December 25, 2025 03:25
Changing an app's icon in iOS 10.3 without showing the system alert dialog
// Change the app icon without showing the system alert
// The trick is to call setAlternateIconName(_:completionHandler:), then
// immediately show (then immediately hide) a temp ViewController.
// This seems to interrupt the system dialog box, which never shows.
if UIApplication.shared.supportsAlternateIcons {
UIApplication.shared.setAlternateIconName("nameOfAlternateIcon")
let tempViewController = UIViewController()