Skip to content

Instantly share code, notes, and snippets.

View jagbolanos's full-sized avatar

Jorge Garcia jagbolanos

View GitHub Profile
@jagbolanos
jagbolanos / gist:1773924
Created February 8, 2012 21:12
Create a UDID for the Device
/*
UNIQUE IDENTIFIER
*/
+ (NSString*) deviceIdentifier {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *deviceId = [defaults objectForKey:DEVICE_ID_KEY];
if (!deviceId) {
//Create unique ID
CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
@jagbolanos
jagbolanos / gist:1773938
Created February 8, 2012 21:14
Get Battery Level
+ (float_t) batteryLevel {
UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
return [myDevice batteryLevel];
}
@jagbolanos
jagbolanos / gist:1784229
Created February 9, 2012 23:28
Background Task and then Timer
UIBackgroundTaskIdentifier bgTask;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
self.updateLocationTimer = [NSTimer scheduledTimerWithTimeInterval:UPDATE_INTERVAL target:self selector:@selector(shouldStartLocationUpdate) userInfo:nil repeats:YES];
@jagbolanos
jagbolanos / gist:2050221
Created March 16, 2012 14:12
Java is by-value, by-reference or by-sharing? Illustrated with C++
#include <iostream>
class Objeto {
public:
int x;
};
void objeto_por_valor_modificar_miembro(Objeto o) {
o.x = 20;
@jagbolanos
jagbolanos / gist:2050263
Created March 16, 2012 14:23
Java is by-value, by-reference or by-sharing? Illustrated with C++ (ENGLISH)
#include <iostream>
class MyObject {
public:
int x;
};
void object_by_value_modify_member(MyObject o) {
o.x = 20;
@jagbolanos
jagbolanos / gist:2494164
Created April 25, 2012 22:55
Custom Navigation Bar
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: NAVIGATION_BAR_BACKGROUND];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
@jagbolanos
jagbolanos / gist:2649319
Created May 9, 2012 22:15
UITextView with Hint Text
- (void) viewDidLoad {
//...
comments.text = @"Comments";
comments.textColor = [UIColor lightGrayColor];
isEmpty = YES;
//...
}
- (BOOL)textViewShouldBeginEditing:(UITextView*)textView {
if (isEmpty) {
@jagbolanos
jagbolanos / gist:2789661
Created May 25, 2012 18:24
Image with borders not affected by resize
progressImage.image = [[UIImage imageNamed:@"black_progress_bar"] resizableImageWithCapInsets:UIEdgeInsetsMake(0., leftCap, 0., leftCap)];
@jagbolanos
jagbolanos / gist:2951816
Created June 19, 2012 01:34
Parse ISO8601 Date
+ (NSDate*) parseISO8601DateString:(NSString*)dateString {
ISO8601DateFormatter *formatter = [[ISO8601DateFormatter alloc] init];
formatter.parsesStrictly = YES;
NSDate *date = [formatter dateFromString:dateString];
[formatter release];
return [[date retain] autorelease];
}
@jagbolanos
jagbolanos / gist:2975193
Created June 22, 2012 21:02
Check iOS Version
CGFloat systemVersion = [[[ UIDevice currentDevice ] systemVersion ] floatValue ];
if (systemVersion < 5.0) {
} else {
}