Instantly share code, notes, and snippets.

View gist:5077983
[SVProgressHUD show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
for(id object in objects) {
// CPU heavy code
dispatch_async(dispatch_get_main_queue(), ^ {
[SVProgressHUD showProgress:x];
});
}
View rescuer.rb
rescue_from Exception, :with => :mail_exception
def mail_exception(exception)
mail = Mail.new do
from 'Rescuer (domain.com) <rescuer@domain.com>'
to 'user@domain.com'
subject exception.inspect
body exception.backtrace[0..10].join("\n")
end
View gist:1747988
- (void)queryDidReceiveNotification:(NSNotification *)notification {
NSArray *results = [self.metadataQuery results];
for(NSMetadataItem *item in results) {
NSString *filename = [item valueForAttribute:NSMetadataItemDisplayNameKey];
NSNumber *filesize = [item valueForAttribute:NSMetadataItemFSSizeKey];
NSDate *updated = [item valueForAttribute:NSMetadataItemFSContentChangeDateKey];
NSLog(@"%@ (%@ bytes, updated %@)", filename, filesize, updated);
}
}
View iCloud Metadata.m
self.metadataQuery = [[NSMetadataQuery alloc] init];
[metadataQuery setPredicate:[NSPredicate predicateWithFormat:@"%K LIKE '*'", NSMetadataItemFSNameKey]];
View gist:1747982
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(queryDidReceiveNotification:)
name:NSMetadataQueryDidUpdateNotification
object:self.metadataQuery];
View gist:1691280
self.view.layer.anchorPoint = CGPointMake(0.50, 1.0);
CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
bounceAnimation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.05],
[NSNumber numberWithFloat:1.08],
[NSNumber numberWithFloat:0.92],
[NSNumber numberWithFloat:1.0],
nil];
View gist:1612967
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat maxY = scrollView.contentSize.height+scrollView.contentInset.bottom;
CGFloat botY = scrollView.contentOffset.y+scrollView.frame.size.height;
NSLog(@"y = %f, maxY = %f", botY, maxY);
if(botY >= maxY) {
// load next page
}
}
View gist:1612933
- (void)viewDidLoad {
self.currentPage = 0;
self.dataSource = [[NSMutableArray alloc] init];
}
- (void)fetchData {
[[SVHTTPClient sharedClient] GET:@"https://api.github.com/users/AndrewGertig/watched"
parameters:[NSDictionary dictionaryWithValue:[NSNumber numberWithInt:self.currentPage] forKey:@"page"]
completion:^(id response, NSError *error) {
[self.dataSource addObjectsFromArray:response];
View gist:1495276
@interface Class ()
@property (nonatomic, readonly) NSDateFormatter *dateFormatter;
@end
@implementation Class
@synthesize dateFormatter;
View SVHTTPRequest.m
[SVHTTPRequest GET:@"http://github.com/api/v2/json/repos/show/samvermette/SVHTTPRequest"
parameters:nil
completion:^(id response, NSError *error) {
NSNumber *watchers = [[response valueForKey:@"repository"] valueForKey:@"watchers"];
NSLog(@"SVHTTPRequest has %@ watchers", watchers);
}];