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
@schwa
schwa / libfuzzer.md
Last active February 27, 2024 18:45
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.

import SwiftUI
import Combine
public struct ChangeObserver<V: Equatable>: ViewModifier {
public init(newValue: V, action: @escaping (V) -> Void) {
self.newValue = newValue
self.newAction = action
}
private typealias Action = (V) -> Void
@dabrahams
dabrahams / FactoryInitialization.swift
Last active October 22, 2022 13:46
Class factory initializers
/// Classes whose initializers actually create derived classes
protocol FactoryInitializable {
/// The type of the least-derived class declared to be FactoryInitializable.
///
/// - Warning: Do not define this in your FactoryInitializable type!
associatedtype FactoryBase: AnyObject, FactoryInitializable = Self
// This associatedtype is a trick that captures `Self` at the point where
// `FactoryInitializable` enters a class hierarchy; in other contexts, `Self`
// refers to the most-derived type.
}
@dabrahams
dabrahams / Dispatch.swift
Created April 25, 2020 13:37
Post-hoc specialized behavior based on refinement
/// A repository of functionality depending on the conformances of `Model`.
///
/// Conditional conformances provide implementation functions that take a
/// generic argument type with the safe assumption that the argument's concrete
/// type is `Model`.
struct Dispatch<Model> {
/// Returns `f(a as! Model) as! R1`
///
/// Used by implementation functions to avoid the clutter of casting
/// explicitly.
func testIsBidirectional() {
func assert<C: Collection>(_ collection: C, isBidirectional: Bool) {
XCTAssertEqual(collection.isBidirectional, isBidirectional)
}
assert([1, 2, 3], isBidirectional: true)
assert(Set([1, 2, 3]), isBidirectional: false)
}
extension Collection {
//
// ContentView.swift
// Layout
//
// Created by Matt Gallagher on 7/6/19.
// Copyright © 2019 Matt Gallagher. All rights reserved.
//
import SwiftUI
As of iOS 11/macOS High Sierra, and only including ones in Foundation and CoreFoundation
Strings:
_NSCFString - a CFStringRef or CFMutableStringRef. This is the most common type of string object currently.
- May have 8 bit (ASCII) or 16 bit (UTF-16) backing store
_NSCFConstantString - a compile time constant CFStringRef, like you'd get with @"foo"
- May also be generated by dynamic string creation if matches a string in a pre-baked table of common strings called the StringROM
NSBigMutableString - an NSString backed by a CFStorage (https://github.com/opensource-apple/CF/blob/master/CFStorage.h) for faster handling of very large strings
NSCheapMutableString - a very limited NSMutableString that allows for zero-copy initialization. Used in NSFileManager for temporarily wrapping stack buffers.
@nubbel
nubbel / xcbuild-debugging-tricks.md
Created June 9, 2017 08:36 — forked from ddunbar/xcbuild-debugging-tricks.md
Xcode new build system debugging tricks

New Build System Tricks

Command Line

# enable internal menu
defaults write com.apple.dt.Xcode ShowDVTDebugMenu -book YES

alias xcbuild=$(xcode-select -p)/../SharedFrameworks/XCBuild.framework/Versions/A/Support/xcbuild
@inamiy
inamiy / SwiftElmFrameworkList.md
Last active March 11, 2024 10:20
React & Elm inspired frameworks in Swift
@chockenberry
chockenberry / finder_icons.sh
Last active February 10, 2024 19:05
A simple shell script to turn the Finders desktop icons on and off
#!/bin/sh
defaults read com.apple.finder CreateDesktop > /dev/null 2>&1
enabled=$?
if [ "$1" = "off" ]; then
if [ $enabled -eq 1 ]; then
defaults write com.apple.finder CreateDesktop false
osascript -e 'tell application "Finder" to quit'
open -a Finder