Skip to content

Instantly share code, notes, and snippets.

View coryhymel's full-sized avatar

Cory coryhymel

  • Crowdbotics
  • Charlotte, NC
View GitHub Profile
@coryhymel
coryhymel / gist:a84129402d272ad4e6135d7ac1e1d686
Created August 23, 2016 19:26
Recursive function to preload array of PFObjects
/**
Recusivly pre load an array of PFObjects.
- parameter items: The items to preload.
- parameter completion: Invoked once all loading in the background has been completed. If an error occured it will be passed back otherwise `success` will be `true` with a `nil` error parameter.
*/
func preloadItems(items: [PFObject], completion: (success: Bool, error: NSError?) -> ()) {
func recursiveLoad(index: Int) {
@coryhymel
coryhymel / Device Type Macro
Created May 7, 2014 21:16
Macros to check device types
#ifndef IS_WIDESCREEN
#define IS_WIDESCREEN (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < DBL_EPSILON)
#endif
#ifndef IS_IPHONE
#define IS_IPHONE ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"])
#endif
#ifndef IS_IPOD
#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])
@coryhymel
coryhymel / Background to Main GCD Block
Last active August 29, 2015 13:55
Background/Main GCD Block
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//background processing goes here
dispatch_async(dispatch_get_main_queue(), ^{
//update UI here
});
});
@coryhymel
coryhymel / GCD Semaphore
Last active January 4, 2016 04:29
GCD Semaphore for finding items around you based on distance
NSArray *stores = ...;
CLLocation *myLocation = ...;
NSMutableArray *nearestStores = [NSMutableArray array];
CLRegion *nearest100kmRegion = [CLRegion initCircularRegionWithCenter:[myLocation coordinate]
radius:100000
identifier:@"someIdentifier"];
// We will need to enumerate all stores to ensure that there are no more
// than 25 objects within the defined region.
@coryhymel
coryhymel / GCD Waiting
Last active January 4, 2016 04:29
Waiting for multiple GCD blocks to finish
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();
// Add a task to the group
dispatch_group_async(group, queue, ^{
// Some asynchronous work
});
// Do some other work while the tasks execute.
@coryhymel
coryhymel / CategoryImplementingMethodOverride
Created April 9, 2013 17:21
Suppress warning: “Category is implementing a method which will also be implemented by its primary class”
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
// do your override
#pragma clang diagnostic pop
@coryhymel
coryhymel / ShakeAnimation
Created March 27, 2013 03:39
A way to make any object to "shake". In this example we use a UILabel.
UILabel *myLabel....
CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"position"];
[shake setDuration:0.1];
[shake setRepeatCount:2];
[shake setAutoreverses:YES];
[shake setFromValue:[NSValue valueWithCGPoint:
CGPointMake(myLabel.center.x - 5,myLabel.center.y)]];
[shake setToValue:[NSValue valueWithCGPoint:
CGPointMake(myLabel.center.x + 5, myLabel.center.y)]];
@coryhymel
coryhymel / daysBetweenDate
Created October 10, 2012 20:15
Find number of days between two NSDates
- (NSInteger)daysBetweenDate:(NSDate*)fromDateTime andDate:(NSDate*)toDateTime
{
NSDate *fromDate;
NSDate *toDate;
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar rangeOfUnit:NSDayCalendarUnit startDate:&fromDate
interval:NULL forDate:fromDateTime];
[calendar rangeOfUnit:NSDayCalendarUnit startDate:&toDate