Skip to content

Instantly share code, notes, and snippets.

View romyilano's full-sized avatar
😎
improving

Romy romyilano

😎
improving
View GitHub Profile
@romyilano
romyilano / merge2Images.m
Created December 21, 2012 22:03
Merge 2 Images into one image / iOS
// source
// http://stackoverflow.com/questions/9257992/how-to-combine-merge-2-images-into-1
- (UIImage*)imageByCombiningImage:(UIImage*)firstImage withImage:(UIImage*)secondImage {
UIImage *image = nil;
CGSize newImageSize = CGSizeMake(MAX(firstImage.size.width, secondImage.size.width), MAX(firstImage.size.height, secondImage.size.height));
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]);
} else {
UIGraphicsBeginImageContext(newImageSize);
@romyilano
romyilano / album.m
Created December 30, 2012 15:23
adding a photo from an album
- (IBAction)addAlbumFoto:(id)sender {
// summon mr. imagepicker!
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePicker setDelegate:self];
[self presentViewController:imagePicker animated:YES completion:nil];
@romyilano
romyilano / textView.m
Created January 3, 2013 16:41
This makes editing the textview fill up the entire screen
//
// ViewController.m
// erica-Sadun-textViewExample
//
// Created by Romy Ilano on 1/3/13.
// Copyright (c) 2013 Romy Ilano. All rights reserved.
//
#import "ViewController.h"
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{ // The iOS device = iPhone or iPod Touch
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 480)
{ // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
@romyilano
romyilano / viewcontroller.m
Created January 5, 2013 16:51
CIImage loading from a png file in objective-C
NSString *path = [[NSBundle mainBundle] pathForResource:@"kittymike_536x536" ofType:@"png"];
NSURL *fileURL = [NSURL fileURLWithPath:path];
CIImage *image = [CIImage imageWithContentsOfURL:fileURL];
@romyilano
romyilano / gist:4526921
Created January 13, 2013 23:55
A nice way to automatically turn your logs on and off instead of having to hand-erase them
// Do this in the -Prefix.pch file
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
// From Matt Neuberg / from Jens Alfke
// when you want the logs to be turned on then you set if(0) to 0
// when you want them turned off you set if(1)
@romyilano
romyilano / blocks.m
Created February 6, 2013 17:19
blocks in Objective-C :: includes a block storage qualifier. Nice illustration of how blocks can access variables that are within the scope as long as you have a storage qualifier __block established beforehand from apress.com beginning ios 5 development - Dave Mark | Jack Nutting | Jeff LaMarche
// define a variable that can be changed by a block
__block int a = 0;
// define a block that tries to modify a variable
// in its scope
void (^sillyBlock)(void) = ^{ a = 47 };
// check the value of our variable before calling the block
NSLog(@"a == %d", a); // outputs " a == 0 "
@romyilano
romyilano / nullinsql.m
Created February 6, 2013 19:45
Dealing with null values in an SQL database for objective-C Often there are nil values in SQL For some reason the excellent NSNULL NullSafe open source library didn't do the trick for me Source: http://stackoverflow.com/questions/6107416/using-sign-percentage-symbol-in-a-sql-query-with-objective-c
char *ortData = (char *)sqlite3_column_text(statement, 3);
NSString *ort = ortData == NULL ? nil : [[NSString alloc] initWithUTF8String:ortData];
@romyilano
romyilano / bignerdranchblock.m
Created February 8, 2013 19:42
A beautiful example of blocks in Big Nerd Ranch. I like how they describe blocks as a hybridization of method handling in procedural and object-oriented programming languages. Methods in C and procedural langauges can be accessed anywhere but methods in object-oriented progrmaming langauges can only be accessed by classes and instances of classe…
// block variables - this one isn't defined
// block variable named adder that takes in an int parameter and an int b parameter
int (^adder)(int a, int b);
// defining block literals - here's the syntax
^int (int x, int y) {
return x + y;
};
@romyilano
romyilano / nsdictionaryjson.m
Created February 9, 2013 05:24
Thanks to one of the raywenderlich.com authors -> here's a nice NSDIctionary category extension that easily turns json data into convenient dictionaries toJSON: can be used on an NSDIctionary instance to get JSON data
// extend NSdictionary (foundation) class
@interface NSDictionary(JSONCategories)
+(NSDictionary *)dictionaryWithContentsOfJSONURLString:(NSString *)urlAddress;
-(NSData *)toJSON;
@end
@implementation NSDictionary(JSONCategories)
+(NSDictionary *)dictionaryWithContentsOfJSONURLString:(NSString *)urlAddress
{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlAddress]];