This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSString *)stringForTimeIntervalSinceCreated:(NSDate *)dateTime serverTime:(NSDate *)serverDateTime{ | |
NSInteger MinInterval; | |
NSInteger HourInterval; | |
NSInteger DayInterval; | |
NSInteger DayModules; | |
NSInteger interval = abs((NSInteger)[dateTime timeIntervalSinceDate:serverDateTime]); | |
if(interval >= 86400) { | |
DayInterval = interval/86400; | |
DayModules = interval%86400; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL) validateEmail: (NSString *) candidate { | |
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; | |
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; | |
return [emailTest evaluateWithObject:candidate]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString*)base64forData:(NSData*)theData { | |
const uint8_t* input = (const uint8_t*)[theData bytes]; | |
NSInteger length = [theData length]; | |
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | |
NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4]; | |
uint8_t* output = (uint8_t*)data.mutableBytes; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIImage *)scaleImage:(UIImage*)image toResolution:(int)resolution { | |
CGImageRef imgRef = [image CGImage]; | |
CGFloat width = CGImageGetWidth(imgRef); | |
CGFloat height = CGImageGetHeight(imgRef); | |
CGRect bounds = CGRectMake(0, 0, width, height); | |
//if already at the minimum resolution, return the orginal image, otherwise scale | |
if (width <= resolution && height <= resolution) { | |
return image; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SET A - SET B ------------------------ | |
// an array that contains many objects | |
NSMutableArray *arForAll = [NSMutableArray arrayWithObjects:@"1",@"2",@"Nimit",@"sagar",@"3", nil]; | |
// an array which is sort of subset of above array. | |
NSMutableArray *selForSelected = [NSMutableArray arrayWithObjects:@"Nimit",@"sagar", nil]; | |
// create a set with array - major set. | |
NSMutableSet* set1 = [NSMutableSet setWithArray:arForAll]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sample data is as follows | |
//// <h1>some data</h1> <h2>some other data</h2> | |
// and if you wish to extract data as follows | |
//// some data some other data | |
// use following class for decoding HTML string to normal text | |
@interface STEntitiesConverter : NSObject <NSXMLParserDelegate> | |
@property (nonatomic, retain) NSMutableString* resultString; | |
- (NSString*)convertEntiesInString:(NSString*)s; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSMutableArray *)loadAndParseWithStringData:(NSString*)stringData hasHeaderFields:(BOOL)hasHeaderFields{ | |
NSArray *gcRawData = [stringData componentsSeparatedByString:@"\n"]; | |
NSArray *singleGC = [NSArray array]; | |
NSMutableArray *allGC = [NSMutableArray array]; | |
for (int i = 0; i < gcRawData.count; i++) | |
{ | |
NSString *nextGCString = [NSString stringWithFormat:@"%@", gcRawData[i]]; | |
singleGC = [nextGCString componentsSeparatedByString:@","]; | |
NSMutableArray *arrayOfComponents = [NSMutableArray array]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// timeline_twitter_api.m | |
// Twitter demo | |
// | |
// Created by SagarRK on 09/10/13. | |
// Copyright (c) 2013 http://sugartin.info . All rights reserved. | |
// | |
#import "timeline_twitter_api.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// timeline_twitter_api.h | |
// Twitter demo | |
// | |
// Created by SagarRK on 09/10/13. | |
// Copyright (c) 2013 http://sugartin.info . All rights reserved. | |
// | |
#import <Foundation/Foundation.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Original source code courtesy John from iOSDeveloperTips.com */ | |
#include <sys/socket.h> | |
#include <sys/sysctl.h> | |
#include <net/if.h> | |
#include <net/if_dl.h> | |
+ (NSString *)getMacAddress | |
{ | |
int mgmtInfoBase[6]; |