Skip to content

Instantly share code, notes, and snippets.

View simonpang's full-sized avatar

Simon Pang simonpang

  • Hong Kong
View GitHub Profile
@simonpang
simonpang / gist:3756413
Created September 20, 2012 14:57
parsing RFC3339 date
- (NSDate *)parseDate:(NSString *)object {
if ([object isKindOfClass:[NSString class]]) {
// See workaround for parsing RFC3339 dates:
// http://stackoverflow.com/questions/4330137/parsing-rfc3339-dates-with-nsdateformatter-in-ios-4-x-and-macos-x-10-6-impossib
NSError *error = nil;
NSDate *date = nil;
[[self dateFormatter] getObjectValue:&date forString:object range:nil error:&error];
return date;
}
@simonpang
simonpang / gist:3755012
Created September 20, 2012 09:58
Download photo from S3
NSString *url = [NSString stringWithFormat:@"http://XXXX.s3-ap-southeast-1.amazonaws.com/%@", path];
[cell.imageView setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil];
@simonpang
simonpang / gist:3754259
Created September 20, 2012 06:28
Use custom image in navigation bar
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBar"] forBarMetrics:UIBarMetricsDefault];
@simonpang
simonpang / gist:3754256
Created September 20, 2012 06:26
Debug network connections using AFNetwork
- (void)enableNetworkDebug {
[[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingOperationDidStartNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
AFHTTPRequestOperation *op = [note object];
NSLog(@"\n\nREQUEST:%x \n%@\n\n", (NSUInteger)op.request, [TTTURLRequestFormatter cURLCommandFromURLRequest:op.request]);
}];
@simonpang
simonpang / gist:3754248
Created September 20, 2012 06:22
Upload photo to server
#pragma mark DLCImagePickerControllerDelegate
-(void) imagePickerControllerDidCancel:(DLCImagePickerController *)picker{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
[self dismissModalViewControllerAnimated:YES];
}
- (void)uploadMediaInfo:(NSDictionary *)info {
UIImage *resizedImage = [[info objectForKey:@"image"] imageCroppedToFitSize:CGSizeMake(800, 800)];
NSData *jpegData = UIImageJPEGRepresentation(resizedImage, 0.5);
@simonpang
simonpang / gist:3383699
Created August 18, 2012 00:50
Rubymotion build time use cases
Simons-MacBook-Air:ruby simon$ git clone https://github.com/siuying/motion-github-followers
Testing Environment
====================
* OS X 10.8
* Xcode 4.4
* 1.6Ghz Core i5 (MBA 11", Mid 2011)
* 4GB memory