Skip to content

Instantly share code, notes, and snippets.

@boctor
boctor / BaseViewController.m
Created May 5, 2011 02:08
A base view controller class that when running on the simulator in debug mode, will auto simulate a memory warning every time the view controller's viewDidAppear is called
//
// BaseViewController.m
//
// Created by Peter Boctor on 5/4/11.
//
// Copyright (c) 2011 Peter Boctor
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@rsms
rsms / KVOChangeScope.hh
Created November 25, 2010 01:24
Conveniently mark Key-Value Observable properties as edited in Objective-C++
/*
* KVOChangeScope -- Conveniently mark edits for Key-Value Observations in
* Objective-C++ in custom setters.
*
* Example:
*
* - (void)setFoo:(id)value {
* kvo_scoped_change(foo);
* // your setter code here which might return at any moment
* }
@rsms
rsms / sleeping-barber.m
Created November 10, 2010 19:04
Sleeping barber with GCD (Grand Central Dispatch)
int main (int argc, const char * argv[]) {
dispatch_queue_t waitingChairs = dispatch_queue_create("waitingChairs", 0);
dispatch_queue_t barber = dispatch_queue_create("barber", 0);
dispatch_semaphore_t semaphore = dispatch_semaphore_create(3);
NSInteger ident = 0;
while (++ident) {
if (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW) != 0) {
printf("Customer %d turned away\n", ident);
continue;
}