Skip to content

Instantly share code, notes, and snippets.

@aufflick
aufflick / AssociationHelpers.swift
Last active November 6, 2021 06:55
Helpers to assist using the ObjC runtime to associate both objects and structs in Swift
// Associated wrapper by WeZZard : https://wezzard.com/2015/10/09/associated-object-and-swift-struct/
// Type safe helpers inspired by Tikitu de Jager : https://medium.com/@ttikitu/swift-extensions-can-add-stored-properties-92db66bce6cd#.mx6ekrw16
public final class AssociatedStruct<T>: NSObject, NSCopying {
public typealias Type = T
public let value: Type
public init(_ value: Type) { self.value = value }
@aufflick
aufflick / symbolicate_activity_monitor_sample.pl
Created February 11, 2015 09:20
Script to symbolicate output from Activity Monitor.app's sample dumps
#!/usr/bin/perl -w
use strict;
use warnings;
# The human has to determine the UUID from the binary images section for now. Sue me.
my ($uuid, $sample_file_path) = @ARGV;
die "Usage:\n $0 'main bundle uuid' 'path to sample.txt'"
unless $uuid && -f $sample_file_path;
@aufflick
aufflick / testGCDDeterminism.swift
Created October 11, 2018 00:27
XCTest Expectation bug
import XCTest
import Foundation
class GCDTestTests: XCTestCase {
func testGCDDeterminism() {
// Just for sanity, confirming *everything* is happening on the serial main thread.
assert(Thread.isMainThread)
var seen = [Int]()
@aufflick
aufflick / testGCDDeterminism.swift
Created October 10, 2018 18:01
testGCDDeterminism.swift
import XCTest
class GCDTestTests: XCTestCase {
func testGCDDeterminism() {
// Just for sanity, confirming *everything* is happening on the serial main thread.
assert(Thread.isMainThread)
for _ in 0..<1_000 {
let expectations = (0..<1_000).map { self.expectation(description: "Expect \($0)") }
for i in 0..<1_000 {
DispatchQueue.main.async {
@aufflick
aufflick / emacs-pipe.pl
Last active February 9, 2018 23:44
Piping to an emacs buffer with emacsclient
#!/usr/bin/env perl
# You can use this script in a pipe. It's input will become an emacs buffer
# via emacsclient (so you need server-start etc.)
# See http://mark.aufflick.com/o/886457 for more information
# Copyright (C) 2011 by Mark Aufflick <mark@aufflick.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
#import <Foundation/NSObject.h>
@interface Fraction: NSObject {
int numerator;
int denominator;
}
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
@aufflick
aufflick / make_chilkat_objc_docset.pl
Created November 28, 2014 03:19
Make a Dash compatible docset from ChilKat's ObjC library html documentation
#!/usr/bin/perl -w
=head1 NAME
make_chilkat_objc_docset - Make a Dash compatible docset from ChilKat's ObjC library html documentation
=head1 SYNOPSIS
./make_chilkat_objc_docset.pl
extension UIView {
convenience init(translateMasks: Bool, frame: CGRect = CGRectZero) {
self.init(frame: frame)
self.translatesAutoresizingMaskIntoConstraints = translateMasks
}
}
/*
get {
return (objc_getAssociatedObject(self, &ourObserverItemKey)
as? AssociatedStruct<SomeStructType>)
.map {$0.value}
}
set {
objc_setAssociatedObject(self,
&ourObserverItemKey,
newValue.map
@aufflick
aufflick / reveal.py
Last active January 1, 2016 04:18 — forked from chrismiles/reveal.py
""" File: reveal.py
Add to ~/.lldbinit:
command script import ~/.lldb-scripts/reveal.py
Q: Want to automatically load the Reveal lib on launch while debugging from Xcode?
A: In Xcode:
Add a Symbolic Breakpoint
Symbol: "UIApplicationMain"
Action: Debugger Command with value "reveal"