Skip to content

Instantly share code, notes, and snippets.

View cbowns's full-sized avatar

Christopher Bowns cbowns

View GitHub Profile
///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - Warn if we KVO a weak property
// Doesn't support key paths.
static BOOL PSPDFIsWeakProperty(id object, NSString *keyPath) {
objc_property_t property = class_getProperty([object class], keyPath.UTF8String);
if (property) {
// https://developer.apple.com/library/mac/documentation/cocoa/conceptual/objcruntimeguide/articles/ocrtpropertyintrospection.html
const char *attributes = property_getAttributes(property);
return attributes && strstr(attributes, ",W");
@steipete
steipete / gist:9021032
Created February 15, 2014 15:43
Run Script that converts TODO or FIXME or ??? into a warning. Super useful.
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
@mattstevens
mattstevens / gist:989296
Created May 24, 2011 18:15
Monitoring for IP address changes
#import "NetworkMonitor.h"
NSString *NetworkConfigurationDidChangeNotification = @"NetworkConfigurationDidChangeNotification";
void storeCallback(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) {
[(NetworkMonitor *)info update];
}
@implementation NetworkMonitor
static void PSPDFFixCenteringInPrinterBrowserViewController(void) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Patch the `UIPrinterSearchingView` class so we get a sane label placement in iOS 7.
Class printerSearchingViewClass = NSClassFromString([NSString stringWithFormat:@"UI%@Searching%@", @"Printer", @"View"]);
if (printerSearchingViewClass) {
SEL customLayoutSubviewsSEL = NSSelectorFromString(@"pspdf_layoutSubviews");
id customLayoutSubviews = ^(UIView *_self) {
((void( *)(id, SEL))objc_msgSend)(_self, customLayoutSubviewsSEL); // call original.
@try {
@lennypham
lennypham / gist:7026020
Created October 17, 2013 14:31
Macro for converting hex color values into a UIColor object.
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#pragma mark -
#pragma mark CGFloat
#pragma mark Trigonometric Functions
#define CGFloatCos(a) (CGFLOAT_IS_DOUBLE ? cos(a) : cosf(a))
#define CGFloatSin(a) (CGFLOAT_IS_DOUBLE ? sin(a) : sinf(a))
#define CGFloatTan(a) (CGFLOAT_IS_DOUBLE ? tan(a) : tanf(a))
#define CGFloatACos(a) (CGFLOAT_IS_DOUBLE ? acos(a) : acosf(a))
#define CGFloatASin(a) (CGFLOAT_IS_DOUBLE ? asin(a) : asinf(a))
#define CGFloatATan(a) (CGFLOAT_IS_DOUBLE ? atan(a) : atanf(a))
@bewebste
bewebste / backup_growl.rb
Created May 7, 2012 18:47
Script to display Time Machine progress messages as Growl notifications
#!/usr/bin/ruby
#Just run this script in a terminal window, leaving the window open in the
#background so it can continue to process messages.
IO.popen("syslog -F \'$(Sender): $Message\' -w -k Sender com.apple.backupd") { |syslogIO|
while (inputString = syslogIO.gets) do
escapedString = inputString.gsub("'", "\\'")
`/usr/local/bin/growlnotify -a 'Time Machine' -m '#{escapedString}'`
end
}
@wooster
wooster / gist:1359532
Created November 11, 2011 22:34
Miscellaneous iOS Notes

Debugging

No Exception Backtraces in iOS 5

There's a bug in the iOS 5 SDK where symbols aren't showing up in the debugger for exception backtraces.

To work around it, go into the breakpoint navigator in Xcode 4, then down at the bottom left, click on the + button and choose "Add Exception Breakpoint…". Set it to break "On Throw", and you should get a breakpoint where the exception is thrown.

Entitlements