Skip to content

Instantly share code, notes, and snippets.

View CaptainMalReynolds's full-sized avatar

Malcolm Reynolds CaptainMalReynolds

  • Vancouver, Canada
View GitHub Profile

Keybase proof

I hereby claim:

  • I am captainmalreynolds on github.
  • I am mrreynolds (https://keybase.io/mrreynolds) on keybase.
  • I have a public key ASCdXRGkHMo0IInB8R2xxCGJGMprvdeXOfoW_WDjKrrGWQo

To claim this, I am signing this object:

let defaultPriority = DISPATCH_QUEUE_PRIORITY_DEFAULT
let backgroundQueue = dispatch_get_global_queue(defaultPriority, 0)
dispatch_async(backgroundQueue, {
let result = doSomeExpensiveWork()
dispatch_async(dispatch_get_main_queue(), {
//use `result` somehow
})
})
extension NSUserDefaults {
@nonobjc subscript(key: String) -> AnyObject? {
get {
return objectForKey(key)
}
set {
setObject(newValue, forKey: key)
}
}
- (UIViewController *)currentController {
UIResponder *currentController = [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] nextResponder];
if ([currentController isMemberOfClass:[UINavigationController class]]) {
NSArray *navStack = ((UINavigationController *)currentController).viewControllers;
currentController = [navStack objectAtIndex:[navStack count] - 1];
}
if ([currentController isKindOfClass:[UIViewController class]])
return (UIViewController *)currentController;
return nil;
@CaptainMalReynolds
CaptainMalReynolds / Rounded avatar
Last active August 29, 2015 13:57
Rounded_avatar
self.avatarImageView.layer.cornerRadius = 150.0f;
self.avatarImageView.layer.borderWidth = 2.0f;
self.avatarImageView.layer.borderColor = [UIColor blackColor].CGColor;
self.avatarImageView.clipsToBounds = YES;
@CaptainMalReynolds
CaptainMalReynolds / email_validation
Created March 17, 2014 06:47
Validate e-mail address
- (BOOL) validEmail:(NSString*) emailString {
if([emailString length]==0){
return NO;
}
NSMutableArray *storeArray = [[NSMutableArray alloc] init];
int x;
for (int i=0; [storeArray count] < 10; i++)
{
x = arc4random_uniform(10);
if(![storeArray containsObject:[NSNumber numberWithInt:x]])
{
[storeArray addObject:[NSNumber numberWithInt:x]];
}