View gist:2588474
// Please don’t do this. | |
// Need to change UISearchBar’s cancel button text? | |
// Well, there’s no API for that. | |
// (Sorry UIKit.) | |
UISearchBar *searchBar = [self.searchDisplayController searchBar]; | |
for (UIView *view in [searchBar subviews]) { … <left as an exercise to the adventurous> } |
View UIImage+MPImageNamedNilCheck.h
// | |
// UIImage+MPImageNamedNilCheck.h | |
// | |
// Created by Christopher Bowns on 5/6/12. | |
// Copyright (c) 2012 Mechanical Pants Software. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIImage (MPImageNamedNilCheck) |
View backup_growl.rb
#!/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' -t 'Time Machine' -m '#{escapedString}'` | |
end | |
} |
View gist:2706112
// JSON is dangerous, take one of these! | |
+ (id)nullGuardedDict:(NSDictionary *)dict valueForKey:(NSString *)key; | |
{ | |
id obj = nil; | |
obj = [dict valueForKey:key]; | |
if (obj == [NSNull null]) { | |
obj = nil; | |
} | |
return obj; |
View IPInsetLabel.h
// | |
// IPInsetLabel.h | |
// Instapaper | |
// | |
// Created by Marco Arment on 7/23/11. | |
// Copyright 2011 Instapaper LLC, released to the public domain. | |
// | |
#import <UIKit/UIKit.h> |
View gist:2963045
/* | |
System Versioning Preprocessor Macros via http://stackoverflow.com/questions/3339722/check-iphone-ios-version | |
Example: | |
if (UIDeviceSystemVersionLessThan(@"4.0")) { | |
// code for pre-4.0 devices. | |
} | |
if (UIDeviceSystemVersionGreaterThanOrEqualTo(@"3.1.1")) { | |
// Code for 3.1.1. |
View gist:2992390
- (CGPoint)center:(CGPoint)oldCenter movedFromAnchorPoint:(CGPoint)oldAnchorPoint toAnchorPoint:(CGPoint)newAnchorPoint withFrame:(CGRect)frame; | |
{ | |
CGPoint anchorPointDiff = CGPointMake(newAnchorPoint.x - oldAnchorPoint.x, newAnchorPoint.y - oldAnchorPoint.y); | |
CGPoint newCenter = CGPointMake(oldCenter.x + (anchorPointDiff.x * frame.size.width), | |
oldCenter.y + (anchorPointDiff.y * frame.size.height)); | |
return newCenter; | |
} |
View UIApplication+NetworkActivity.h
// | |
// UIApplication+NetworkActivity.h | |
// | |
// Created by Christopher Bowns on 4/11/12. | |
// Original implementation: http://stackoverflow.com/a/6978817/774 | |
// Copyright (c) 2012 Mechanical Pants Software | |
// | |
#import <UIKit/UIKit.h> |
View gist:5289226
# In the debugger: | |
# (fill in <home> and <image> below with your user path and the image's ivar | |
p (BOOL)[(NSFileManager *)[NSFileManager defaultManager] createFileAtPath:@"<home>/Desktop/image.png" contents:(void *)UIImagePNGRepresentation(<image>) attributes:nil] |
View gist:6056535
// An example of a model object with a boolean property | |
// that's backed by an NSNumber from a JSON response | |
@interface ModelObject : NSObject | |
@property (nonatomic, assign, getter = isEnabled) BOOL enabled; | |
@end | |
@interface ModelObject () |