Skip to content

Instantly share code, notes, and snippets.

View jagbolanos's full-sized avatar

Jorge Garcia jagbolanos

View GitHub Profile
@jagbolanos
jagbolanos / gist:3035847
Created July 2, 2012 21:33
searchbar no box
searchBar.barStyle = UIBarStyleBlackTranslucent;
searchBar.backgroundColor = [UIColor clearColor];
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
@jagbolanos
jagbolanos / gist:3036204
Created July 2, 2012 22:46
Enable search button when empty text
- (void) enableSearchEmpty {
UITextField *searchBarTextField = nil;
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:[UITextField class]])
{
searchBarTextField = (UITextField *)subview;
break;
}
}
@jagbolanos
jagbolanos / gist:3125548
Created July 16, 2012 22:39
Create Unique ID
+ (NSString*) getUniqueID {
CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef newUniqueIdString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
NSString *uniqueId = [NSString stringWithFormat:@"%@",(NSString *)newUniqueIdString];
CFRelease(newUniqueId);
CFRelease(newUniqueIdString);
return [[uniqueId retain] autorelease];
}
@jagbolanos
jagbolanos / gist:3694862
Created September 10, 2012 23:43
Apply an overlay to an image that has alpha only on the visible parts
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
#import <stdlib.h>
- (CGImageRef) createMaskWithImageAlpha: (CGContextRef) originalImageContext {
UInt8 *data = (UInt8 *)CGBitmapContextGetData(originalImageContext);
float width = CGBitmapContextGetBytesPerRow(originalImageContext) / 4;
float height = CGBitmapContextGetHeight(originalImageContext);
@jagbolanos
jagbolanos / gist:3725568
Created September 14, 2012 23:22
Binary Tree
data BinaryTree a = BinaryNode a (BinaryTree a) (BinaryTree a) | BinaryNullNode
instance Show a => Show (BinaryTree a) where
show BinaryNullNode = " null"
show (BinaryNode a l r) = " (" ++ show a ++ show l ++ show r ++ ")"
search BinaryNullNode _ = False
search (BinaryNode a l r) v
| v == a = True
| v < a = search l v
@jagbolanos
jagbolanos / gist:3757616
Created September 20, 2012 18:44
Change system font to views
+ (void) setFont:(NSString*)fontName andFactor:(CGFloat)factor toView:(UIView*)view {
NSArray *subviews = view.subviews;
for (NSObject *subview in subviews) {
if ([subview isKindOfClass:[UILabel class]]) {
UILabel *label = (UILabel*)subview;
[label setFont:[UIFont fontWithName:fontName size:label.font.pointSize*factor]];
}
if ([subview isKindOfClass:[UIView class]]) {
[Util setFont:fontName andFactor:factor toView:(UIView*)subview];
}
- (void) postToTwitterPhotoAtIndexPath: (NSIndexPath*) indexPath {
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
PFObject *photo = [self.myPhotos objectAtIndex:indexPath.row];
// Create an account store object.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
def sumarListas(l:List[Int], m:List[Int]) : List[Int] = (l, m) match {
case (Nil, Nil) => Nil
case (Nil, y :: ys) => y :: sumarListas(Nil, ys)
case (y :: ys, Nil) => y :: sumarListas(ys, Nil)
case (x :: xs, y :: ys) => (x+y) :: sumarListas(xs, ys)
}
def extraerImpares(l:List[Int]) : List[Int] = l match {
case Nil => Nil
case x :: xs => if ( x % 2 != 0) x :: extraerImpares(xs) else extraerImpares(xs)
case class NB(e:Int, izq:NB, der:NB)
def busquedaBinaria(v:Int, a:NB) : NB = {
if (a == null)
a
else {
if (v == a.e)
NB(v,null,null)
else {
if (v < a.e)
//Examen Final
//6 Oro Devuelve el elemento maximo de una lista
//e.g. maximo (List(3,4,1,2,9,11,7,5,0)) => 11
def maximoHelper(l:List[Int], max:Int) : Int = l match {
case Nil => max
case x :: xs => if (x > max) maximoHelper(xs, x) else maximoHelper(xs, max)
}