Skip to content

Instantly share code, notes, and snippets.

View jagbolanos's full-sized avatar

Jorge Garcia jagbolanos

View GitHub Profile
@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: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: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: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: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: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:1773906
Created February 8, 2012 21:10
Get Mac Address
+ (NSString *)getMacAddress
{
int mgmtInfoBase[6];
char *msgBuffer = NULL;
size_t length;
unsigned char macAddress[6];
struct if_msghdr *interfaceMsgStruct;
struct sockaddr_dl *socketStruct;
NSString *errorFlag = NULL;
@jagbolanos
jagbolanos / gist:1755953
Created February 6, 2012 23:45
Load Facebook object
+(BOOL) loadSession {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults objectForKey:ACCESS_TOKEN_KEY] ||
![defaults objectForKey:EXPIRATION_DATE_KEY] ||
![defaults objectForKey:FACEBOOK_USER]) {
[Util clearSession];
return NO;
}
Facebook *facebook = [[Util sharedInstance] facebook];
@jagbolanos
jagbolanos / gist:1755208
Created February 6, 2012 21:58
Publish photo to facebook
- (void) publishToFacebook:(NSData*)image withMessage:(NSString*)message {
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setValue:message forKey:@"message"];
[params setValue:image forKey:@"source"];
[[[Util sharedInstance] facebook] requestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
[params release];
}
@jagbolanos
jagbolanos / gist:1754933
Created February 6, 2012 21:15
TabBarViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UITabBarController *tbc = [[UITabBarController alloc] init];
UINavigationController *nvc = [[UINavigationController alloc] init];
StreamViewController *vc = [[StreamViewController alloc] init];
vc.title = @"Vampire Or Not";
[nvc pushViewController:vc animated:NO];