Skip to content

Instantly share code, notes, and snippets.

View frr149's full-sized avatar

Fernando Rodriguez Romero frr149

View GitHub Profile
@frr149
frr149 / transparentModalViewController.m
Created October 20, 2011 18:58
How to create a transparent modal View Controller
#pragma mark - Transparent Modal View
-(void) presentTransparentModalViewController: (UIViewController *) aViewController
animated: (BOOL) isAnimated
withAlpha: (CGFloat) anAlpha{
self.transparentModalViewController = aViewController;
UIView *view = aViewController.view;
view.opaque = NO;
view.alpha = anAlpha;
@frr149
frr149 / gist:1892504
Created February 23, 2012 11:43
reverse geocoding with CoreLocation
-(void) addressFromLocation: (CLLocation *) aLocation{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
self.activity.hidden = NO;
[self.activity startAnimating];
self.output.text = @"Ahora lo averiguo. Contactando con Paco Lobatón...";
[geocoder reverseGeocodeLocation:aLocation
completionHandler:^(NSArray *placemarks, NSError *error) {
NSError *err = nil;
NSURL *aURL = [NSURL URLWithString:@"http://www.google.com"];
NSString *contents = [NSString stringWithContentsOfURL:aURL
encoding:NSUTF8StringEncoding
error:&err];
-(NSString *) fetchStringFrom: (NSURL *) aURL error: (NSError **) err{
// Haz algo raro que pueda cascar
if (YES) {
// Se ha producido un error
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:NSLocalizedDescriptionKey
forKey:@"Error al hacer algo arriesgado"];
// recordad que se trata de una doble indirección, así que hay que usar *err
*err = [NSError errorWithDomain:@"Mi dominio"
NSError *err = nil;
NSURL *aURL = [NSURL URLWithString:@"http://www.google.com"];
NSString *contents = [NSString stringWithContentsOfURL:aURL
encoding:NSUTF8StringEncoding
error:&err];
// Esto es incorrecto!!!!!
if (err) {
// Creo que ha habido un error
NSLog(@"Creo que ha habido un error:%@", err.localizedDescription);
NSError *err = nil;
NSURL *aURL = [NSURL URLWithString:@"http://www.google.com"];
NSString *contents = [NSString stringWithContentsOfURL:aURL
encoding:NSUTF8StringEncoding
error:&err];
// Esto sí que es correcto: inspeccionar el valor del retorno
if (!contents) {
// Seguro que ha habido un error
NSLog(@"Ahora sí que se ha producido un error:%@", err.localizedDescription);
NSError *err = nil;
NSURL *aURL = [NSURL URLWithString:@"http://www.google.com"];
NSString *contents = [NSString stringWithContentsOfURL:aURL
encoding:NSUTF8StringEncoding
error:&err];
// Esto sí que es correcto: inspeccionar el valor del retorno
if (!contents) {
// Seguro que ha habido un error
NSLog(@"Ahora sí que se ha producido un error:%@", err.localizedDescription);
NSError *err = nil;
NSURL *aURL = [NSURL URLWithString:@"http://www.google.com"];
NSString *contents = [NSString stringWithContentsOfURL:aURL
encoding:NSUTF8StringEncoding
error:&err];
// Esto sí que es correcto: inspeccionar el valor del retorno
if (!contents) {
// Seguro que ha habido un error
NSLog(@"Ahora sí que se ha producido un error:%@", err.localizedDescription);
@frr149
frr149 / gist:3436543
Created August 23, 2012 13:20
Mandelbrot
-(void)generateImageOfSize:(CGSize)imageSize
{
// Determine integer size of image
NSInteger imageIntWidth = ceilf(imageSize.width);
NSInteger imageIntHeight = ceilf(imageSize.height);
// Determine coordinate maxima
assert(zoomFactor > 0.0f);
float coordMaxX = coordMinX + imageIntWidth / zoomFactor;
float coordMaxY = coordMinY + imageIntHeight / zoomFactor;
@frr149
frr149 / gist:3436544
Created August 23, 2012 13:21
Mandelbrot
-(void)generateImageOfSize:(CGSize)imageSize
{
// Determine integer size of image
NSInteger imageIntWidth = ceilf(imageSize.width);
NSInteger imageIntHeight = ceilf(imageSize.height);
// Determine coordinate maxima
assert(zoomFactor > 0.0f);
float coordMaxX = coordMinX + imageIntWidth / zoomFactor;
float coordMaxY = coordMinY + imageIntHeight / zoomFactor;