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 / libfuzzer.md
Created April 8, 2023 16:28 — forked from schwa/libfuzzer.md
Using LLVM's libfuzzer with Swift

Using LLVM's libfuzzer with Swift

Background

Of the many tools available for fuzzing, I've found that LLVM's libfuzzer is the easiest to use for Swift on macOS. Other tools seem to have a list of requirements taht are difficult to meet. libfuzzer on the other hand is built into LLVM and is available on macOS in the custom Swift toolchains: https://www.swift.org/download/

In this document I'll describe how to use libfuzzer with Swift and Swift Packages.

I used this setup to fuzz an SVG Renderer package that I am building. I was able to find and fix a number of bugs in my SVG parsing code using libfuzzer in basically no time at all.

@mayoff
mayoff / UnitPoint.angle.swift
Last active July 16, 2023 15:07
point on unit square at a given angle
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
// 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
# 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>
@mayoff
mayoff / README.md
Last active August 23, 2021 14:41
defining an extra-large widget only if on iOS 15

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)
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
@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
#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 {