Skip to content

Instantly share code, notes, and snippets.

View AlanQuatermain's full-sized avatar

Jim Dovey AlanQuatermain

View GitHub Profile
@AlanQuatermain
AlanQuatermain / ChangeLicenses.rb
Created January 6, 2013 17:27
I needed to go through a large number of Xcode-generated source-code files the other day, replacing the copyright line with a license header statement. Since there were lots of files in a nested structure I decided to use a script, and I added in a glob pattern to exclude certain files/folders— because there was some public domain source in ther…
#!/usr/bin/ruby
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@AlanQuatermain
AlanQuatermain / update_package_archive.rb
Created January 6, 2013 16:52
A simple script which will change the root-paths of components in a PackageMaker document at the base of a new Xcode Archive, all without opening PackageMaker itself. Very useful for projects where you have a lot of separate components (and thus separate .xcarchive folders), which can take a while to update from the PackageMaker application afte…
#!/usr/bin/ruby
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@protocol APRemoteAddressBook <NSObject>
- (void) allPeople: (void (^)(NSArray *, NSError *)) reply;
- (void) mailingAddressesForPersonWithIdentifier: (NSString *) identifier
reply: (void (^)(NSArray *, NSError *)) reply;
- (void) emailAddressesForPersonWithIdentifier: (NSString *) identifier
reply: (void (^)(NSArray *, NSError *)) reply;
- (void) phoneNumbersForPersonWithIdentifier: (NSString *) identifier
reply: (void (^)(NSArray *, NSError *)) reply;
@end
@AlanQuatermain
AlanQuatermain / gist:2912081
Created June 11, 2012 19:15
Check whether the iOS Dev Centre is available yet, for 30 minutes
-- Thirty minute timeout
with timeout of 108000 seconds
repeat while true
delay 5
set baseurl to "https://developer.apple.com/devcenter/ios/index.action"
set curlshellcode to "curl " & baseurl
set theshellresult to do shell script curlshellcode
if theshellresult does not contain "maintenance" then
State of my main queue while running a block (at the start of main() before it all goes pear-shaped)
(lldb) expr (void) dispatch_debug((void *)dispatch_get_current_queue(), "main q")
=== log file opened for Kobo[7195] at 1337357109.056275 ===
com.apple.main-thread[0xad009600] = { xrefcnt = 0xffffffff, refcnt = 0xffffffff, suspend_cnt = 0x0, locked = 1, target = com.apple.root.default-overcommit-priority[0xad009b00], width = 0x0, running = 0x0, barrier = 1 }: main q
@AlanQuatermain
AlanQuatermain / trololol.m
Created May 18, 2012 13:39
A non-zero-based array. Guess what base it uses-- it could be anything!
@interface AQNonZeroBasedArray : NSArray
@end
@implementation AQNonZeroBasedArray
{
NSArray * _realArray;
NSUInteger _base;
}
// initialize it using AQNonZeroBasedArray * array = @[obj1, obj2, obj3];
Thread 18 name: Dispatch queue: com.apple.root.high-priority
Thread 18 Crashed:
0 libdispatch.dylib 0x31bb9bb2 dispatch_resume$VARIANT$mp + 46
1 AVFoundation 0x31aa64ae __61-[AVPlayerOccasionalCaller _resetTimerForPlayerNewRate:time:]_block_invoke_0 + 478
2 libdispatch.dylib 0x31bb5c52 _dispatch_call_block_and_release + 6
3 libdispatch.dylib 0x31bb8810 _dispatch_worker_thread2 + 252
4 libsystem_c.dylib 0x37ecddf4 _pthread_wqthread + 288
5 libsystem_c.dylib 0x37ecdcc8 start_wqthread + 0
// This works:
NSURL * base = [NSURL URLWithString: @"http://[::1]:49981/"];
NSURL * full = [base URLByAppendingPathComponent: @"test.html"];
NSLog(@"full = %@", full); // prints "full = http://[::1]:49981/"
// This does not:
NSURL * base = [NSURL URLWithString: @"" relativeToURL: [NSURL URLWithString: @"http://[::1]:49981/"];
NSURL * full = [base URLByAppendingPathComponent: @"test.html"];
NSLog(@"full = %@", full); // prints "full = (null)"
@AlanQuatermain
AlanQuatermain / gist:2369294
Created April 12, 2012 17:20
Compatibility macros for NSNumber literals
#if __has_feature(objc_bool)
# define $YES @YES
# define $NO @NO
# define $i(x) @##x
# define $ui(x) @##x
# define $l(x) @##x
# define $ul(x) @##x
# define $ll(x) @##x
# define $ull(x) @##x
# define $f(x) @##x
@AlanQuatermain
AlanQuatermain / gist:2219930
Created March 27, 2012 20:18
Setting up rulesets for line-breaking Japanese text
+ (void) initialize
{
if ( self != [KHLineBreaker class] )
return;
typedef BOOL (^charsetClassMatchingRule)(NSCharacterSet * charset, NSAttributedString * attrStr, NSUInteger index);
charsetClassMatchingRule inCharset = ^(NSCharacterSet * charset, NSAttributedString * attrStr, NSUInteger index) {
return ( [charset characterIsMember: [[attrStr string] characterAtIndex: index]] );
};
BOOL (^isOrnamentedCharacterComplex)(NSAttributedString*, NSUInteger) = ^BOOL(NSAttributedString * attrStr, NSUInteger index) {