Skip to content

Instantly share code, notes, and snippets.

View badeen's full-sized avatar

Jonathan Badeen badeen

View GitHub Profile
@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
@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;
@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: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);
}
#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: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
@badeen
badeen / gist:3876259
Created October 11, 2012 23:20
MixPanel iOS problems
Actual API Problems
- It raises an exception when you pass in an empty string for sharedInstanceWithToken. This is just a horrible practice. I had previously been using an empty string so that I wouldn't track data from our test server/app. NEVER EVER RAISE AN EXCEPTION. Just NSLog it and return nil if you must.
- It raises an exception when calling sharedInstance before sharedInstanceWithToken. NEVER EVER RAISE AN EXCEPTION. Just NSLog it and return nil if you must.
- I see no good reason to have a separate object and methods for MixpanelPeople. This seems like some sort of weird name spacing attempt or something like that. This is not done in Objective-C. It is wrong.
- set:to: and set: are horrible, horrible method names. Just read the Objective-C coding guidelines by Apple. This is just plain wrong.
- The defines like DebugLog need to use an #ifndef. DebugLog is a commonly used thing by developers and you are attempting to redefine it. Be a good citizen and don't do that.
Doc Problems
- (IBAction)open:(id)sender
{
CATransform3D perspectiveTransform = CATransform3DIdentity;
perspectiveTransform.m34 = 1.0f / -2000.0f;
CATransform3D endScaleTransform = CATransform3DMakeScale(0.8f, 0.8f, 1.0f);
CATransform3D startTransform = perspectiveTransform;
CATransform3D endTransform = CATransform3DConcat(endScaleTransform, perspectiveTransform);
CATransform3D middleTransform = CATransform3DConcat(CATransform3DMakeRotation(M_PI_4 / 2.0f, 1, 0, 0), endTransform);
- (NSInteger)numberOfSectionsInCollectionView:(PSTCollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(PSTCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [_photos count];
}
Suppose I make an app like Instagram. As soon as a photo is taken I upload the original to the server. What's good about this is that it gets it that much closer to being ready to be viewed by others. You can simultaneously allow the user to do other stuff while that's being done. The user now applies and modifies the photo using Core Image filters. When the user finishes instead of uploading a new copy of the modified photo you simply send the information necessary to recreate the effect on the server. Almost instantly that image will be available on the server for others to see. The user won't have to wait for something to upload. You also now have the benefit of having the original photo which maybe you show side by side or allow the user to modify at a later point.
This is just one instance off the top of my head. I'm sure there are many more useful things that could be done when interfacing with iOS apps specifically.