Skip to content

Instantly share code, notes, and snippets.

View jlcampana's full-sized avatar
:octocat:
emu emu emu...

Jose Luis Campaña jlcampana

:octocat:
emu emu emu...
View GitHub Profile
@jlcampana
jlcampana / UIBarButtonItem+Image.m
Created September 18, 2012 08:46
UIBarButtonItem+Image.m
// UIBarButtonItem+Image.m
@implementation UIBarButtonItem (Image)
-(id)initWithImage:(UIImage *)image title:(NSString*)title target:(id)target action:(SEL)action {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame= CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.titleLabel.font = [UIFont boldSystemFontOfSize:12];
button.titleLabel.shadowOffset = CGSizeMake(0, -1);
button.titleLabel.shadowColor = [UIColor colorWithWhite:0 alpha:0.5];
@jlcampana
jlcampana / NSMutableArray+Stack.h
Created September 18, 2012 08:17
NSMutableArray+Stack.h
//
// NSMutableArray+Stack.h
// shell poc
//
// Created by Jose Luis Campaña on 9/18/12.
// Copyright (c) 2012 Jose Luis Campaña. All rights reserved.
//
#import <Foundation/Foundation.h>
@jlcampana
jlcampana / NSMutableArray+Stack.m
Created September 18, 2012 08:16
NSMutableArray+Stack.m
//
// NSMutableArray+Stack.m
// shell poc
//
// Created by Jose Luis Campaña on 9/18/12.
// Copyright (c) 2012 Jose Luis Campaña. All rights reserved.
//
#import "NSMutableArray+Stack.h"
@jlcampana
jlcampana / gist:3705738
Created September 12, 2012 10:12
Scroll to a textfield on a table when tapped
//We need some properties
@property (nonatomic,strong) NSMutableArray *dataSource;
@property (nonatomic, strong) UITextField *currentTextField;
@property (nonatomic) CGRect originalTableFrame;
@property (nonatomic) NSIndexPath *indexForCurrentTextField;
@property (nonatomic) NSTimeInterval keyboardAnimationDuration;
//Don't forget to be delegate of UITextFieldDelegate
//Then...
@jlcampana
jlcampana / gist:3690379
Created September 10, 2012 11:16
Locate the most left non transparent pixel of a UIImage
+ (CGPoint)getMostLeftTransparentPixelOfImage:(UIImage*)image
{
int xx = 0;
int yy = 0;
int count = image.size.width * image.size.height;
// First get the image into your data buffer
CGImageRef imageRef = [image CGImage];
@jlcampana
jlcampana / gist:3690295
Created September 10, 2012 10:54
Locate first transparent pixel on a UIImage
+ (CGPoint)getFirstTransparentPixelOfImage:(UIImage*)image
{
int xx = 0;
int yy = 0;
int count = image.size.width * image.size.height;
// First get the image into your data buffer
CGImageRef imageRef = [image CGImage];
@jlcampana
jlcampana / gist:3618589
Created September 4, 2012 08:39
Time ago
+(NSString *)getTimeAgo:(NSDate *)fecha
{
NSString *timeAgo;
float since_mins,since_hours, since_days, since_months, since_years;
NSTimeInterval since = fabs([fecha timeIntervalSinceNow]);
since_mins = (since / 60);
since_hours = (since_mins / 60);
since_days = (since_hours / 24);
since_months = (since_days / 31);
@jlcampana
jlcampana / gist:3618570
Created September 4, 2012 08:37
Orientation
+(BOOL)orientationIsPortrait
{
return UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]);
}
+ (UIInterfaceOrientation) interfaceOrientation
{
return [[UIApplication sharedApplication] statusBarOrientation];
}
@jlcampana
jlcampana / gist:3618564
Created September 4, 2012 08:36
Get free memory
+(natural_t) getFreeMemory
{
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
vm_statistics_data_t vm_stat;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) {
@jlcampana
jlcampana / gist:3618562
Created September 4, 2012 08:35
getRandomIntBetween 2 ints
+(NSInteger)getRandomIntBetween:(NSInteger)min andMax:(NSInteger)max
{
return min + arc4random() % ((max + 1) - min);
}