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

Using LLVM's libfuzzer with Swift


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:

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 / 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
// Also see
let s = sin(angle.radians)
let c = cos(angle.radians)
mayoff / main.swift
Created December 23, 2022 05:29
AOC 2022 day 23
import AOC
import Preamble
let input = readInput()
let xinput = """
mayoff / gist:5d56cc66721bdd5e785030ffbeb02dc2
Last active November 17, 2021 23:33
pikchr source for a diagram
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 / 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 / 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" "">
<plist version="1.0">
mayoff /
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:

struct MyWidgets: WidgetBundle {
    var body: some Widget {
mayoff / EqualIconWidthDomain.swift
Created August 12, 2021 04:39
Complete code for (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 / 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 / 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
#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 {