Skip to content

Instantly share code, notes, and snippets.

@mluton
mluton / gist:3372019
Created August 16, 2012 17:47
JAVA_HOME for Mountain Lion
export JAVA_HOME=/Library/Java/Home
@mluton
mluton / gist:3408357
Created August 20, 2012 22:05
Create OHAttributedLabel With NSAttributedString
NSMutableAttributedString *attrStr1 = [NSMutableAttributedString attributedStringWithString:@"inflation"];
[attrStr1 setFont:[UIFont fontWithName:@"CortinaSlate-Regular" size:62.8]];
OHAttributedLabel *label1 = [[[OHAttributedLabel alloc] initWithFrame:CGRectMake(90, 100, 588, 90)] autorelease];
label1.attributedText = attrStr1;
label1.backgroundColor = [UIColor clearColor];
label1.textColor = [UIColor blackColor];
[self.view addSubview:label1];
@mluton
mluton / gist:3866998
Created October 10, 2012 17:12
Timing Code Execution
NSDate *startTime = [NSDate date];
// Code goes here
NSDate *endTime = [NSDate date];
NSTimeInterval executionTime = [endTime timeIntervalSinceDate:startTime];
NSLog(@"Response Time: %f", executionTime);
@mluton
mluton / gist:3867058
Created October 10, 2012 17:22
AFNetworking Request
[[TTAPIClient sharedInstance] getPath:@"videos.json" parameters:@{@"featured_videos" : @"y"}
success:^(AFHTTPRequestOperation *operation, id response) {
NSLog(@"Response: %@", response);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error fetching stuff!");
NSLog(@"%@", error);
}];
@mluton
mluton / gist:3874325
Created October 11, 2012 17:57
Background Pattern
self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"gingham.png"]];
@mluton
mluton / gist:3908650
Created October 17, 2012 22:11
Detecting Device Orientation: 1
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) {
// do portrait stuff
}
else {
// do landscape stuff
}
}
@mluton
mluton / gist:3908659
Created October 17, 2012 22:12
Detecting Device Orientation: 2
if (UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
// do portrait stuff
}
else {
// do landscape stuff
};
@mluton
mluton / gist:3990658
Created October 31, 2012 23:37
Display UIActivityViewController in a Popover
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[@"something"] applicationActivities:nil];
self.popover = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
self.popover.delegate = self;
[self.popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
@mluton
mluton / gist:4004233
Created November 2, 2012 20:51
Iterate Over Collection
for (TTVideo *video in favorites) {
NSLog(@"video.title: %@", video.title);
}
@mluton
mluton / gist:4020043
Created November 5, 2012 20:07
Center a View With Autolayout Constraints
self.noFavoritesImageViewCenterXConstraint = [NSLayoutConstraint constraintWithItem:self.noFavoritesImageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0];
self.noFavoritesImageViewCenterYConstraint = [NSLayoutConstraint constraintWithItem:self.noFavoritesImageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0];