Skip to content

Instantly share code, notes, and snippets.

View Duraiamuthan's full-sized avatar

Durai Amuthan Duraiamuthan

View GitHub Profile
@Duraiamuthan
Duraiamuthan / 0_reuse_code.js
Created October 10, 2013 10:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Duraiamuthan
Duraiamuthan / gist:6729138
Created September 27, 2013 14:08
to mark a method as unavailable
#import <Foundation/Foundation.h>
@interface SampleClass : NSObject
- (id)init __attribute__((unavailable("init is unavailable")));
@end
@Duraiamuthan
Duraiamuthan / gist:6657383
Created September 22, 2013 06:50
objective c format number as comma added currency
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
double d2 = 3432.89;
NSString *strCurrency = [currencyFormatter stringFromNumber:[NSNumber numberWithDouble:d2]];
NSLog(@"%@", strCurrency);
@Duraiamuthan
Duraiamuthan / Objetive c number formatter
Created September 22, 2013 06:49
Objetctive c format the numbers with commas
NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
double d =324233.89;
int i = 324324324;
NSString *strFloat = [formatter stringFromNumber:[NSNumber numberWithDouble:d]];
NSString *strInt = [formatter stringFromNumber:[NSNumber numberWithInt:i]];
NSLog(@"Float: %@", strFloat);
@Duraiamuthan
Duraiamuthan / gist:6657126
Created September 22, 2013 06:03
Objective C find if a text exists in string
-(BOOL)Contains:(NSString *)StrSearchTerm on:(NSString *)StrText
{
return [StrText rangeOfString:StrSearchTerm options:NSCaseInsensitiveSearch].location==NSNotFound?FALSE:TRUE;
}
NSAlert *alert=[NSAlert alertWithMessageText:@"message" defaultButton:@"Ok" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@"InformativeText"];
NSInteger i=[alert runModal];
if (i==NSAlertDefaultReturn) {
NSLog(@"Ok pressed");
}
else{
NSLog(@"Else pressed");
}
CFUUID
CFUUID is available from iOS 2.0. CoreFoundation package (C style API) provide CFUUID. CFUUIDCreate is the method to create the CFUUIDRef and can get an NSString representation of the created CFUUIDRef like :-
CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
NSString *cfuuidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));
CFUUID is not persisted, every time you call CFUUIDCreate and will get new unique identifier.
e.g. 68883Q11-4D23-5434-9D60-2250E4C90967
@Duraiamuthan
Duraiamuthan / gist:d6dc27b954ca348d494f
Created October 28, 2014 17:11
KeychainUtils for storing and getting credentials
//SFHFKeychainUtils.h
#import <UIKit/UIKit.h>
@interface SFHFKeychainUtils : NSObject {
}
+ (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error;
+ (BOOL) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error;
#!/bin/bash
# https://gist.github.com/949831
# http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/
# command line OTA distribution references and examples
# http://nachbaur.com/blog/how-to-automate-your-iphone-app-builds-with-hudson
# http://nachbaur.com/blog/building-ios-apps-for-over-the-air-adhoc-distribution
# http://blog.octo.com/en/automating-over-the-air-deployment-for-iphone/
# http://www.neat.io/posts/2010/10/27/automated-ota-ios-app-distribution.html
@Duraiamuthan
Duraiamuthan / AddAnnotation
Last active August 29, 2015 14:00
AddAnnotation in Mapview
-(void)MarkMapwithLat:(NSString*)lat withLong:(NSString*)longi
{
NSLog(@"Latitude:%@ Longitude:%@",lat,longi);
CLLocationCoordinate2D coord=CLLocationCoordinate2DMake(lat.floatValue,longi.floatValue);
MKAnnotation *annotation=[[MKAnnotation alloc]initWithCoordinate:coord title:self.Name andsubTitle:customerSnippet];
MKCoordinateRegion viewRegion=MKCoordinateRegionMakeWithDistance(coord,500,500);