This file contains 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 *)createUUID | |
{ | |
// Create universally unique identifier (object) | |
CFUUIDRef uuidObject = CFUUIDCreate(kCFAllocatorDefault); | |
// Get the string representation of CFUUID object. | |
NSString *uuidStr = [(NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject) autorelease]; | |
// If needed, here is how to get a representation in bytes, returned as a structure | |
// typedef struct { |
This file contains 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
UIColor* UIColorFromHex(NSInteger colorInHex) { | |
// colorInHex should be value like 0xFFFFFF | |
return [UIColor colorWithRed:((float) ((colorInHex & 0xFF0000) >> 16)) / 0xFF | |
green:((float) ((colorInHex & 0xFF00) >> 8)) / 0xFF | |
blue:((float) (colorInHex & 0xFF)) / 0xFF | |
alpha:1.0]; | |
} |
This file contains 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
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:filename withExtension:nil]; | |
if (fileURL != nil) | |
{ | |
SystemSoundID theSoundID; | |
OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)fileURL, &theSoundID); | |
if (error == kAudioServicesNoError) | |
soundID = theSoundID; | |
} |
This file contains 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
use Email::Find; | |
sub replaceEmail { | |
my $data = shift @_; | |
my $finder = Email::Find->new( | |
sub { | |
my($email, $orig_email) = @_; | |
my($address) = $email->format; | |
return qq|<a href="mailto:$address">$orig_email</a>|; | |
} | |
); |
This file contains 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
use URI::Find; | |
sub replaceURL { | |
my $data = shift @_; | |
require URI::Find::userContentFile; | |
my $finder = URI::Find::Schemeless->new( | |
sub { | |
my($uri, $orig_uri) = @_; | |
return qq|<a href="$uri">$orig_uri</a>|; | |
} | |
); |
This file contains 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)isValidateEmail:(NSString *)email { | |
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:email]; | |
} |
This file contains 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
// Defining a block variable | |
BOOL (^isInputEven)(int) = ^(int input) | |
{ | |
if (input % 2 == 0) | |
return YES; | |
else | |
return NO; | |
}; |
This file contains 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
// Call similar to a C function call | |
int x = -101; | |
NSLog(@"%d %@ number", x, isInputEven(x) ? @"is an even" : @"is not an even"); |
This file contains 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
float price = 1.99; | |
float (^finalPrice)(int) = ^(int quantity) | |
{ | |
// Notice local variable price is | |
// accessible in the block | |
return quantity * price; | |
}; | |
int orderQuantity = 10; |
This file contains 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
price = .99; | |
NSLog(@"Ordering %d units, final price is: $%2.2f", orderQuantity, finalPrice(orderQuantity)); |