Skip to content

Instantly share code, notes, and snippets.

Avatar
😷
status messages are fun

Rob Mayoff mayoff

😷
status messages are fun
View GitHub Profile
@mayoff
mayoff / UnitPoint.angle.swift
Last active February 27, 2023 07:12
point on unit square at a given angle
View UnitPoint.angle.swift
import SwiftUI
extension UnitPoint {
/// - returns: The point on the perimeter of the unit square that is at angle `angle` relative to the center of the unit square.
init(_ angle: Angle) {
// Inspired by https://math.stackexchange.com/a/4041510/399217
// Also see https://www.desmos.com/calculator/k13553cbgk
let s = sin(angle.radians)
let c = cos(angle.radians)
@mayoff
mayoff / main.swift
Created December 23, 2022 05:29
AOC 2022 day 23
View main.swift
// https://adventofcode.com/2022/day/23
import AOC
import Preamble
let input = readInput()
let xinput = """
....#..
..###.#
#...#.#
@mayoff
mayoff / gist:5d56cc66721bdd5e785030ffbeb02dc2
Last active November 17, 2021 23:33
pikchr source for a diagram
View gist:5d56cc66721bdd5e785030ffbeb02dc2
# https://twitter.com/hillelogram/status/1461103115260805123/photo/1
# https://pikchr.org/home/pikchrshow
linerad = 5px
B1: box "1"
B8: box "8"
B9: box "9"
B1_2: [ box; "1" color blue at last box ]
B2_2: [ box; "2" color blue at last box ]
@mayoff
mayoff / TableDemo.swift
Created November 5, 2021 16:28
demo code for laying out a SwiftUI table with fitted columns
View TableDemo.swift
import SwiftUI
fileprivate struct WidthPreferenceKey: PreferenceKey {
static var defaultValue: [AnyHashable: CGFloat] { [:] }
static func reduce(value: inout [AnyHashable : CGFloat], nextValue: () -> [AnyHashable : CGFloat]) {
value.merge(nextValue(), uniquingKeysWith: { max($0, $1) })
}
}
@mayoff
mayoff / com.dqd.stop-simulator-spotlight.plist
Created November 5, 2021 15:24
A launchd agent (put it in ~/Library/LaunchAgents) to stop simulator Spotlight processes
View com.dqd.stop-simulator-spotlight.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.dqd.stop-simulator-spotlight</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
@mayoff
mayoff / README.md
Last active August 23, 2021 14:41
defining an extra-large widget only if on iOS 15
View README.md

You probably have a WidgetBundle type in your widget extension like this:

@main
struct MyWidgets: WidgetBundle {
    var body: some Widget {
        SmallWidget()
        MediumWidget()
        LargeWidget()
    }
@mayoff
mayoff / EqualIconWidthDomain.swift
Created August 12, 2021 04:39
Complete code for https://stackoverflow.com/a/68751668/77567 (EqualIconWidthDomain for SwiftUI Label views)
View EqualIconWidthDomain.swift
import SwiftUI
fileprivate struct IconWidthKey: PreferenceKey {
static var defaultValue: CGFloat? { nil }
static func reduce(value: inout CGFloat?, nextValue: () -> CGFloat?) {
switch (value, nextValue()) {
case (nil, let next): value = next
case (_, nil): break
case (.some(let current), .some(let next)): value = max(current, next)
@mayoff
mayoff / RefreshableTests.swift
Created July 19, 2021 18:35
for pointfree episode 153
View RefreshableTests.swift
@testable import SwiftUICaseStudies
import XCTest
class RefreshableTests: XCTestCase {
func testVanilla() async {
var k: CheckedContinuation<Void, Never>? = nil
let viewModel = PullToRefreshViewModel(
fetch: {
@mayoff
mayoff / TEA.swift
Last active December 7, 2021 14:25
An implementation of Point-Free's Composable Architecture, with the addition of subscriptions from The Elm Architecture (TEA). See https://github.com/pointfreeco/episode-code-samples/issues/51
View TEA.swift
#if canImport(Combine)
import Combine
import CasePaths
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public typealias Effect<Output> = AnyPublisher<Output, Never>
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension Effect {
@mayoff
mayoff / ContentView.swift
Created February 26, 2020 16:36
SwiftUI gradients spanning multiple views
View ContentView.swift
import SwiftUI
struct BubbleFramesValue {
var framesForKey: [AnyHashable: [CGRect]] = [:]
var gradientFrame: CGRect? = nil
}
struct BubbleFramesKey { }
extension BubbleFramesKey: PreferenceKey {