Skip to content

Instantly share code, notes, and snippets.

Christopher Bowns cbowns

Block or report user

Report or block cbowns

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cbowns
cbowns / gist:6056535
Created Jul 22, 2013
A model object with a BOOL property backed by an NSNumber in the implementation
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 ()
@cbowns
cbowns / gist:5289226
Created Apr 2, 2013
Serializing an image's contents in the iOS Simulator
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]
@cbowns
cbowns / UIApplication+NetworkActivity.h
Created Sep 19, 2012
UIApplication+NetworkActivity
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>
@cbowns
cbowns / gist:2992390
Created Jun 26, 2012
Helper function for moving UIView/CALayer centers when changing anchorPoints
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;
}
@cbowns
cbowns / gist:2963045
Created Jun 21, 2012
UIDevice System Version Preprocessor Macros
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.
@cbowns
cbowns / IPInsetLabel.h
Created May 25, 2012 — forked from marcoarment/IPInsetLabel.h
IPInsetLabel: a simple UILabel subclass that adds padding insets and auto-height-resizing
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>
@cbowns
cbowns / gist:2706112
Created May 15, 2012
Nil-guarded dictionary key-value retrieval for JSON responses
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;
@cbowns
cbowns / backup_growl.rb
Created May 15, 2012 — forked from bewebste/backup_growl.rb
Script to display Time Machine progress messages as Growl notifications
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
}
@cbowns
cbowns / UIImage+MPImageNamedNilCheck.h
Created May 7, 2012
A nil-checking [UIImage imageNamed:] category. Uses thrown and caught exceptions to break into the debugger if you have exception breakpoints turned on. Use #define UIIMAGE_IMAGENAMED_NILCHECK 0 to turn off the throw-and-catch.
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 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> }
You can’t perform that action at this time.