Skip to content

Instantly share code, notes, and snippets.

View funkydevil's full-sized avatar
🤠

Kirill funkydevil

🤠
View GitHub Profile
@funkydevil
funkydevil / KeychainItemWrapper.h
Created July 24, 2012 08:37 — forked from dhoerl/KeychainItemWrapper.h
KeychainItemWrapper ARCified
/*
File: KeychainItemWrapper.h
Abstract:
Objective-C wrapper for accessing a single keychain item.
Version: 1.2 - ARCified
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1){
//load resources for earlier versions
} else {
//load resources for iOS 7
}
@funkydevil
funkydevil / NSString+PhoneNumber.m
Created February 6, 2015 13:17
Removes all characters except those that are allowed in a telephone number
-(NSString *)cleanPhoneNumber
{
if (self.length == 0)
return nil;
NSMutableCharacterSet *mutableCharacterSetForCleanPhoneNumber = [NSMutableCharacterSet new];
[mutableCharacterSetForCleanPhoneNumber addCharactersInString:@"+0123456789"];
[mutableCharacterSetForCleanPhoneNumber invert];
return [[self componentsSeparatedByCharactersInSet:mutableCharacterSetForCleanPhoneNumber] componentsJoinedByString:@""];
- (uint64_t)freeDiskspace
{
uint64_t totalSpace = 0;
uint64_t totalFreeSpace = 0;
__autoreleasing NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
@funkydevil
funkydevil / gist:a394930def3b77e02396
Created March 11, 2015 12:14
show mail composer
-(void)showMailComposer
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate = self;
[mailComposeViewController setSubject:@"My subject"];
[mailComposeViewController setMessageBody:@"Please check log file in attachment" isHTML:NO];
NSData *dataToSend = [Logger logFileData];
- (BOOL)validateEmail:(NSString *)emailStr
{
emailStr = [emailStr lowercaseString];
NSString *emailRegex = @"(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:emailStr];
}
@funkydevil
funkydevil / gist:bfd78e167f601037f909
Created March 26, 2015 08:27
Draw a line in UIView
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0f);
CGContextMoveToPoint(context, 0.0f, 0.0f); //start at this point
@funkydevil
funkydevil / gist:8b44027ad0df6bb95017
Created March 26, 2015 11:36
Check camera access
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == AVAuthorizationStatusAuthorized) {
// do your logic
} else if(authStatus == AVAuthorizationStatusDenied){
// denied
} else if(authStatus == AVAuthorizationStatusRestricted){
// restricted, normally won't happen
} else if(authStatus == AVAuthorizationStatusNotDetermined){
// not determined?!
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
@funkydevil
funkydevil / gist:2219cbc42626a6f95eb0
Created March 30, 2015 14:48
useful define for screen and device identification (http://stackoverflow.com/a/13156390/1928161)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_LANDSCAPE_ORIENTATION (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))