Skip to content

Instantly share code, notes, and snippets.

View badeen's full-sized avatar

Jonathan Badeen badeen

View GitHub Profile
@badeen
badeen / gist:3860863
Created October 9, 2012 19:23
Center image in image view if smaller than image view otherwise proportionally scale
@interface UIImage (ObjColumnist)
- (void)updateWithSpecialScaling;
@end
@implementation UIImage (ObjColumnist)
- (void)updateWithAdjustedScaling
#0 0x32a10960 in objc_exception_throw ()
#1 0x3604bb3c in _PFFaultHandlerLookupRow ()
#2 0x3604d0fe in _PF_FulfillDeferredFault ()
#3 0x36054c10 in _PF_ManagedObject_WillChangeValueForKeyIndex ()
#4 0x3605f332 in _sharedIMPL_setvfk_core ()
#5 0x0009c4f2 in __block_global_0 at /Users/Jonathan/Projects/matchbox_ios/matchbox/matchbox/MBUser.m:60
#6 0x36068bc0 in developerSubmittedBlockToNSManagedObjectContextPerform ()
#7 0x333f04b6 in _dispatch_client_callout ()
#8 0x333f51bc in _dispatch_main_queue_callback_4CF$VARIANT$mp ()
#9 0x346d3f3a in __CFRunLoopRun ()
@badeen
badeen / gist:3622184
Created September 4, 2012 15:10
Resizing map view in table view header and resizing.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint contentOffset = scrollView.contentOffset;
UIView *header = self.tableView.tableHeaderView;
if (contentOffset.y <= 0.0f) {
header.frame = CGRectMake(CGRectGetMinX(header.frame), contentOffset.y, CGRectGetWidth(header.frame), CFY_DISCOVER_TABLE_HEADER_MIN_HEIGHT - contentOffset.y);
[self.mapView setCenterCoordinate:self.mapView.userLocation.coordinate animated:NO];
} else {
header.frame = CGRectMake(CGRectGetMinX(header.frame), 0.0f, CGRectGetWidth(header.frame), CFY_DISCOVER_TABLE_HEADER_MIN_HEIGHT);
}
@interface CFYActivity : NSManagedObject
@property (nonatomic, strong) NSNumber * activityID;
@property (nonatomic, strong) NSNumber * type;
@property (nonatomic, strong) NSDate * date;
@property (nonatomic, strong) NSNumber * amount;
@property (nonatomic, strong) NSString * activityDescription;
@property (nonatomic, strong) NSNumber * rewardID;
@property (nonatomic, strong) CFYChain *chain;
@badeen
badeen / gist:3146387
Created July 19, 2012 19:58
Animation applies a y translation transform. Why?
- (void)animatePhotosIn
{
CAKeyframeAnimation *userPhotoAnim = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
userPhotoAnim.values = [self photoTransformValuesWithMultiplier:1.0];
CAKeyframeAnimation *matchPhotoAnim = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
matchPhotoAnim.values = [self photoTransformValuesWithMultiplier:-1.0];
NSArray *photoAnims = [NSArray arrayWithObjects:userPhotoAnim, matchPhotoAnim, nil];
for (CAKeyframeAnimation *photoAnim in photoAnims) {
photoAnim.calculationMode = kCAAnimationCubic;
@badeen
badeen / gist:3139369
Created July 18, 2012 22:29
Handling emoji correctly
// I take a string from a text field (which includes emoji) and apply this to it so that my JSON parser doesn't freak out when it comes back to me.
NSData *stringData = [message dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *safeString = [[NSString alloc] initWithData:stringData encoding:NSUTF8StringEncoding];
// I try to draw the string I get back from the server (I sent it safeString from above).
// When I draw it I end up getting text like this drawn:
// Test emoji \ud83d\ude03