Skip to content

Instantly share code, notes, and snippets.

View mayoff's full-sized avatar
😷
status messages are fun

Rob Mayoff mayoff

😷
status messages are fun
View GitHub Profile
@mayoff
mayoff / main.swift
Created December 23, 2022 05:29
AOC 2022 day 23
// https://adventofcode.com/2022/day/23
import AOC
import Preamble
let input = readInput()
let xinput = """
....#..
..###.#
#...#.#
@mayoff
mayoff / NSBezierPath-CGPath.swift
Last active September 20, 2022 11:00 — forked from juliensagot/NSBezierPath+cgPath.swift
Convert NSBezierPath to CGPath (Swift 3.0 / Xcode 8b4 syntax)
import AppKit
public extension NSBezierPath {
public var CGPath: CGPath {
let path = CGMutablePath()
var points = [CGPoint](repeating: .zero, count: 3)
for i in 0 ..< self.elementCount {
let type = self.element(at: i, associatedPoints: &points)
switch type {
@mayoff
mayoff / ConversationView.swift
Created February 14, 2020 20:05
playground demonstrating SwiftUI PreferenceKey, EnvironmentKey, and GeometryReader
import SwiftUI
import PlaygroundSupport
struct EqualWidthKey: PreferenceKey {
static var defaultValue: CGFloat? { nil }
static func reduce(value: inout CGFloat?, nextValue: () -> CGFloat?) {
switch (value, nextValue()) {
case (_, nil): break
case (nil, let next): value = next
static CGPathRef createClosedPathWithPoints(const CGPoint *points, size_t count) {
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddLines(path, NULL, points, count);
CGPathCloseSubpath(path);
return path;
}
static CGRect integralFrameForPath(CGPathRef path) {
CGRect frame = CGPathGetBoundingBox(path);
return CGRectIntegral(frame);
@mayoff
mayoff / Arrow.swift
Last active May 13, 2022 07:30
UIBezierPath category to create an arrow (now with a Swift version!)
// Swift 2.2 syntax / API
import UIKit
extension UIBezierPath {
class func arrow(from start: CGPoint, to end: CGPoint, tailWidth: CGFloat, headWidth: CGFloat, headLength: CGFloat) -> Self {
let length = hypot(end.x - start.x, end.y - start.y)
let tailLength = length - headLength
@mayoff
mayoff / EqualIconWidthDomain.swift
Created August 12, 2021 04:39
Complete code for https://stackoverflow.com/a/68751668/77567 (EqualIconWidthDomain for SwiftUI Label views)
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 / 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
#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 / gist:5d56cc66721bdd5e785030ffbeb02dc2
Last active November 17, 2021 23:33
pikchr source for a diagram
# 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
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
<?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>