Skip to content

Instantly share code, notes, and snippets.

View jacksonfdam's full-sized avatar
💻
Coding...

Jackson F. de A. Mafra jacksonfdam

💻
Coding...
View GitHub Profile
# define ALog(format, ...) NSLog((@"%s [L%d] " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
# ifdef DEBUG
# define DLog(format, ...) ALog(format, ##__VA_ARGS__);
# else
# define DLog(...)
# endif
@jacksonfdam
jacksonfdam / gist:2790557
Created May 25, 2012 21:07
Executar som
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"Internet-Jen-1117" ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
[soundPath release];
@jacksonfdam
jacksonfdam / gist:2790564
Created May 25, 2012 21:08
Add a image layer over camera
ImagePicker = [[UIImagePickerController alloc] init];
ImagePicker.delegate = self;
#if TARGET_IPHONE_SIMULATOR
ImagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
#elif TARGET_OS_IPHONE
ImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *ImgOutline=[[UIImageView alloc] initWithFrame:CGRectMake(20, 28, 124, 404)];
ImgOutline.image=[UIImage imageNamed:@"outline.png"];
[ImagePicker.view addSubview:ImgOutline];
#endif
@jacksonfdam
jacksonfdam / gist:2790572
Created May 25, 2012 21:09
UIActionSheet to Display Text Only Messages
UIActionSheet *msg = [[[UIActionSheet alloc]
initWithTitle:@"Lorem ipsum dolor...text goes here"
delegate:nil
cancelButtonTitle:nil destructiveButtonTitle:nil
otherButtonTitles:@"Okay", nil]
autorelease];
[msg showInView:window];
ContentValues values = new ContentValues();
values.put("address", "+550012345678");
values.put("body", "Parabens!");
getContentResolver().insert(Uri.parse("content://sms/sent"),values);
values.put("address", "+550012345678");
values.put("body", "Mais um Teste");
getContentResolver().insert(Uri.parse("content://sms/sent"),values);
values.put("address", "+550012345678");
@jacksonfdam
jacksonfdam / gist:2790642
Created May 25, 2012 21:17
Convert Signed Or Unsigned Integers To Binary In NSString
- (NSString *)intToBinary:(int)number
{
// Number of bits
int bits = sizeof(number) * 8;
// Create mutable string to hold binary result
NSMutableString *binaryStr = [NSMutableString string];
// For each bit, determine if 1 or 0
// Bitwise shift right to process next number
@jacksonfdam
jacksonfdam / gist:2790681
Created May 25, 2012 21:24
Debugging Macros
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Debug
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define DEBUG_ON // Toggle to DEBUG_OFF to hide all debug code
#ifdef DEBUG_ON
#define debug(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);
#else
#define debug(format, ...)
#endif
@jacksonfdam
jacksonfdam / gist:2790687
Created May 25, 2012 21:25
Prefix header
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import "TestFlight.h"
#endif
// Debug
#ifdef DEBUG
# define DLog(...) NSLog(__VA_ARGS__)
@jacksonfdam
jacksonfdam / gist:2819456
Created May 28, 2012 14:30
Fetching Remote Data
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSError *error = nil;
NSURL *url = [NSURL URLWithString:@"http://brandontreb.com/apps/pocket-mud-pro/promo.json"];
NSString *json = [NSString stringWithContentsOfURL:url
encoding:NSASCIIStringEncoding
error:&error];
NSLog(@"\nJSON: %@ \n Error: %@", json, error);
});
@jacksonfdam
jacksonfdam / gist:2819462
Created May 28, 2012 14:30
Parsing JSON
if(!error) {
NSData *jsonData = [json dataUsingEncoding:NSASCIIStringEncoding];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData
options:kNilOptions
error:&error];
NSLog(@"JSON: %@", jsonDict);
}
NSString *promo_url = [jsonDict objectForKey:@"promo_url"];