Skip to content

Instantly share code, notes, and snippets.

View AlanQuatermain's full-sized avatar

Jim Dovey AlanQuatermain

View GitHub Profile
@AlanQuatermain
AlanQuatermain / JavaScriptCore iPhone
Created May 27, 2010 19:38
This is based on SVN checkout of revision 60307
Index: JavaScriptCore/profiler/ProfilerServer.mm
===================================================================
--- JavaScriptCore/profiler/ProfilerServer.mm (revision 60307)
+++ JavaScriptCore/profiler/ProfilerServer.mm (working copy)
@@ -30,7 +30,7 @@
#import "JSRetainPtr.h"
#import <Foundation/Foundation.h>
-#if PLATFORM(IPHONE_SIMULATOR)
+#if !PLATFORM(IPHONE)
@AlanQuatermain
AlanQuatermain / AQPerThreadManagedObjectContext.m
Created May 28, 2010 14:17
A set of simple wrapper functions to get per-thread NSManagedObjectContext instances. When creating main context (i.e. in app delegate) pass it to StoreManagedObjectContextForCurrentThread(). Then just call PerThreadManagedObjectContext() anywhere you nee
static NSString * const AQPerThreadManagedObjectContext = @"AQPerThreadManagedObjectContext";
void StoreManagedObjectContextForCurrentThread( NSManagedObjectContext * context )
{
[[[NSThread currentThread] threadDictionary] setObject: context forKey: AQPerThreadManagedObjectContext];
}
NSManagedObjectContext * PerThreadManagedObjectContext( void )
{
NSManagedObjectContext * result = [[[NSThread currentThread] threadDictionary] objectForKey: AQPerThreadManagedObjectContext];
/*
* NSException+Backtrace.h
* Utilities
*
* Created by Jim Dovey on 8/7/2010.
*
* Copyright (c) 2010 Kobo, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@AlanQuatermain
AlanQuatermain / Location.m
Created September 8, 2010 18:42
A simple class wrapping a movable file/folder location using Aliases.
#import <Foundation/Foundation.h>
#import <CoreServices/CoreServices.h>
@interface Location
{
FSRef fsRef;
HFSUniStr255 name;
}
@property (readonly) FSRef * fileRef;
@AlanQuatermain
AlanQuatermain / SingletonInitializer.m
Created November 2, 2010 14:45
An implementation of a Singleton accessor routine. Provides a dispatch_once-based version and a plain version for pre-(10.6|4.0) systems, with load-time method swapping to install the dispatch version if libdispatch is available at runtime.
#import <libkern/OSAtomic.h>
#import <dispatch/dispatch.h>
#import <objc/runtime.h>
@implementation MySingleton
+ (void) load
{
// check for weak-linked libdispatch symbols
if ( dispatch_queue_create != 0 )
@AlanQuatermain
AlanQuatermain / iOS_42_Simulator_prefix.pch
Created November 2, 2010 15:34
A fix for iOS 4.2 builds against the iOS Simulator: some APIs (look at AVFoundation) are marked as available for 10.7. Sadly the Simulator SDK version of Availability.h doesn't define the 10.7 macros, so it results in horrible compiler errors on all such
#import <Availability.h>
// Fix a bug in the current iOS 4.2 beta SDK where 10.7 version isn't defined
#ifndef __MAC_10_7
#define __MAC_10_7 1070
#if !defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || (__MAC_OS_X_VERSION_MAX_ALLOWED == __MAC_10_6)
#ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
#undef __MAC_OS_X_VERSION_MAX_ALLOWED
@AlanQuatermain
AlanQuatermain / gist:673147
Created November 11, 2010 20:43
A tcpdump log of a print session from an iPad to the Print Simulator running on OS X 10.6.4. Search for UNIRAST to find the start of the image data. Warning— it's a long one.
tcpdump: listening on en2, link-type EN10MB (Ethernet), capture size 1024 bytes
01:27:17.649332 IP6 (hlim 64, next-header TCP (6) payload length: 44) ipaddevcamp-award-ipad.local.51327 > mac-pro.local.8632: Flags [S], cksum 0x68aa (correct), seq 2285601729, win 65535, options [mss 1440,nop,wscale 2,nop,nop,TS val 185853398 ecr 0,sackOK,eol], length 0
0x0000: 6000 0000 002c 0640 fe80 0000 0000 0000 `....,.@........
0x0010: 7e6d 62ff fee2 7698 fe80 0000 0000 0000 ~mb...v.........
0x0020: 021b 63ff feef 2e57 c87f 21b8 883b 83c1 ..c....W..!..;..
0x0030: 0000 0000 b002 ffff 68aa 0000 0204 05a0 ........h.......
0x0040: 0103 0302 0101 080a 0b13 e5d6 0000 0000 ................
0x0050: 0402 0000 ....
01:27:17.649406 IP6 (flowlabel 0xd0d99, hlim 64, next-header TCP (6) payload length: 44) mac-pro.local.8632 > ipaddevcamp-award-ipad.local.51327: Flags [S.], cksum 0x3d24 (correct), seq 1893664218, ack 2285601730, win 65535, options [mss 1440,nop,wscale 3,nop,nop,TS val 4548
@AlanQuatermain
AlanQuatermain / gist:716167
Created November 26, 2010 01:36
A demonstration of some potential issues around the use of -[NSNotificationCenter addObserver:...usingBlock:].
@implementation MyObject
@synthesize observer;
- (void) storeObserverVariable
{
self.observer = [[NSNotificationCenter defaultCenter]
addObserverForName: @"TheNotification"
object: nil
queue: [NSOperationQueue mainQueue]
@AlanQuatermain
AlanQuatermain / gist:809986
Created February 3, 2011 19:15
An Xcode 3 script which will insert a New BSD License comment at the head of a file. Place the caret at the top of your file (or select an existing header comment) and run the script via the Xcode script menu. I have mine in the 'Comments' group, bound
#!/usr/bin/ruby
require 'osx/cocoa'
require 'date'
OSX.require_framework "AddressBook"
filePath = "%%%{PBXFilePath}%%%"
fileName = File.basename(filePath)
projName = File.basename(File.dirname(filePath))
@AlanQuatermain
AlanQuatermain / gist:830865
Created February 17, 2011 02:59
All the external private APIs referenced by iBooks.app version 1.2.1
From PrivateFrameworks/Bom.framework:
U _BOMCopierCopyWithOptions
U _BOMCopierCountFilesInArchive
U _BOMCopierFree
U _BOMCopierNew
U _BOMCopierSetCopyFileFinishedHandler
U _BOMCopierSetCopyFileStartedHandler
U _BOMCopierSetCopyFileUpdateHandler
U _BOMCopierSetFatalErrorHandler
U _BOMCopierSetFatalFileErrorHandler