Skip to content

Instantly share code, notes, and snippets.

View pointless swift benchmarks
import Foundation
class Test
func testing2(var x : Int) -> Int
if x % 3 == 0 {
x += 10
View syncs.d
#!/usr/sbin/dtrace -q -s
CFPreferencesServer$target:::request {
printf("REQUEST from pid %d at %Y ( domain: %s, user: %s, host: %s, container: %s, managed: %d)\n",
arg1 != NULL ? copyinstr(arg1) : "(NULL)",
arg2 != NULL ? copyinstr(arg2) : "(NULL)",
arg3 != NULL ? copyinstr(arg3) : "(NULL)",
arg4 != NULL ? copyinstr(arg4) : "(NULL)",
View clientsyncs.d
#!/usr/sbin/dtrace -q -s
set(char *key, char *domain, char *user, char *host, char *container, char *value)
CFPreferences$target:::set {
printf("Set request at %Y ( key: %s, domain: %s, user:%s, host: %s, container: %s, value: %s)\n", walltimestamp, copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), copyinstr(arg3), copyinstr(arg4), copyinstr(arg5));
Catfish-Man / Controller.m
Created December 30, 2015 08:23
An old boggle project's trie
View Controller.m
#import "Controller.h"
#define INLINE static inline
#define INLINE
static inline int INDEX(char letter) {
View stringbench.swift
import Foundation
func measure(work:Void->Void) {
let start = NSDate()
for _ in 0..<100000 {
let elapsed = -(start.timeIntervalSinceNow)
View tollfree.m
//Given this:
NSArray *objects = @[@1, @2, @3]
//These are equivalent in behavior
NSNumber *first = [objects objectAtIndex:0]
NSNumber *second = (NSNumber *)CFArrayGetValueAtIndex(objects, 0)
//But is the code that runs the same? Not so much… in the first one we do…
objc_msgSend(objects, <selector reference>, 0)
Catfish-Man / sethack.m
Created March 11, 2016 06:21
Demonstrating the trick of using stack-allocated mimics and sets for lookup tables instead of heap allocated keys and dictionaries
View sethack.m
// Compile with clang -framework Foundation sethack.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
CFHashBytes from
#define ELF_STEP(B) T1 = (H << 4) + B; T2 = T1 & 0xF0000000; if (T2) T1 ^= (T2 >> 24); T1 &= (~T2); H = T1;
View sillykeys.m
#import <Foundation/Foundation.h>
static const char *alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
NSString *badKey(int idx) {
char *buffer = malloc(4096);
memset(buffer, 'A', 4096 * sizeof(char));
//NSString hashes the beginning, middle, and end of long strings, so we want our keys to differ only in other places.
//-isEqual: also compares from front to back, so to exaggerate the problem, I placed the differences in the keys about 3/4 of the way through the string
buffer[3072] = alphabet[arc4random_uniform(52)];
View Chicken thighs and brown butter pan sauce tortellini
As seen here:
Loosely based on
Preheat oven to 375F
Chop off a hunk of onion - we had half of one left, so I took about 3/4" off the center, plus a bit more when that looked skimpy
In an oven-safe pan (I used a big cast iron one) saute the onion over medium-low heat in a few tablespoons of unsalted butter until it's brown and translucent
View rootclasskvo.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface KVOTest
@implementation KVOTest