Skip to content

Instantly share code, notes, and snippets.

View timothy1ee's full-sized avatar

Timothy Lee timothy1ee

View GitHub Profile
@timothy1ee
timothy1ee / gist:27a9208a7df5490d8dcd
Created November 12, 2015 22:54
Swift gitignore
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData
## Various settings
*.pbxuser
@timothy1ee
timothy1ee / gist:9057758
Created February 17, 2014 19:53
TTTAttributedLabel example
TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(10, 10, 200, 20)];
label.linkAttributes =
@{ (NSString *)kCTForegroundColorAttributeName : [UIColor redColor],
(NSString *)kCTUnderlineStyleAttributeName : @(kCTUnderlineStyleNone) };
label.enabledTextCheckingTypes = NSTextCheckingAllTypes;
label.text = @"Link to http://google.com";
[self.view addSubview:label];
// adjust the textView width base on screen size and orientation
// the only constant width in the cells is the checkbox (64)
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat width = [self isPortraitOrientation] ? screenRect.size.width : screenRect.size.height;
width -= 64;
CGRect textRect = [textView.text boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]}
context:nil];
@timothy1ee
timothy1ee / gist:8393719
Created January 13, 2014 02:20
Example of using prepareForSegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UITableViewCell *selectedCell = (UITableViewCell *)sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:selectedCell];
Movie *movie = self.movies[indexPath.row];
MovieViewController *movieViewController = (MovieViewController *)segue.destinationViewController;
movieViewController.movie = movie;
}
@timothy1ee
timothy1ee / gist:8308396
Last active January 2, 2016 13:09
Objective C Rotten Tomatoes snippet
NSString *url = @"http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?apikey=dagqdghwaq3e3mxyrp7kmmj5&limit=20&country=us";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
id object = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", object);
}];
@timothy1ee
timothy1ee / 1_tip_calculator_overview.md
Last active December 30, 2015 00:09
Creating the Tip Calculator

Creating the Tip Calculator

Before you get started, download XCode 6 from the Mac App Store. You can buy an iOS Developer Program for $99, but it's not required at this stage.

Start reading about Objective-C. Here's a good quick overview. A more complete primer from Apple is here. If you prefer to learn by video, Lynda has a good overview, it's about 6 hours.

Follow the tip calculator video walkthrough to get the basic tip calculator functionality. After you finish the walkthrough, follow the hints below to add a settings page.

POST /v2/blog/timothy1ee.tumblr.com/post HTTP/1.1
Authorization: OAuth oauth_signature="YhcFwLZ0A08kF8XXDceuIlN8G3Y%3D", oauth_version="1.0", oauth_nonce="221227710", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="BcnUeYPIxBaVCz5sYcs4SkytRqM8azgLclb1PUpeFcknic9RYY", oauth_timestamp="1372109208", oauth_token="RCC7HW8BEWeXWCTR0UVTF4R2JRIn1Mba0N9PmcNpIa3FATNFsR"
Content-Length: 272570
Content-Type: application/x-www-form-urlencoded
Host: api.tumblr.com
Connection: Keep-Alive
User-Agent: android-async-http/1.4.1 (http://loopj.com/android-async-http)
Accept-Encoding: gzip
api_key=BcnUeYPIxBaVCz5sYcs4SkytRqM8azgLclb1PUpeFcknic9RYY&data=%25EF%25BF%25BDPNG%250D%250A%251A%250A%2500%2500%2500%250DIHDR%2500%2500%2500x%2500%2500%2500x%2508%2502%2500%2500%2500%25EF%25BF%25BD%2506%25EF%25BF%25BD%25EF%25BF%25BD%2500%2500%2500%2503sBIT%2508%2508%2508%25EF%25BF%25BD%25EF%25BF%25BDO%25EF%25BF%25BD%2500%2500%2B%2500IDATx%25EF%25BF%25BDL%25EF%25BF%25BD%25EF%25BF%25BD%255Dgu%25EF%25BF%25BD%25EF%25BF%25BD%25EF%25BF%25BD%
@timothy1ee
timothy1ee / LoginActivity.java
Created June 15, 2013 23:05
Sample login activity incorporating Facebook Android SDK
import java.util.Arrays;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import com.facebook.Request;
import com.facebook.Response;
@timothy1ee
timothy1ee / checkin.json
Created December 20, 2012 22:32
Response for: GET '/api/oauth/v1/checkins/<id>.json
{ "checkin" : { "badges" : [ ],
"comment" : "Blabla",
"created_at" : "2012-11-27T01:54:16Z",
"episode_airdate" : "2012-11-25",
"episode_label" : "S02E09",
"episode_num" : 9,
"episode_poster_url" : "http://gomiso.com/uploads/BAhbCFsHOgZmIigyMDEyLzExLzE5LzA2LzM3LzUxLzg5Mi~DrW5kaWNlLmpwZ1sHOgZlOghqcGdbCDoGcDoKdGh1bWIiDjE4MHgxMDAjbg.jpg",
"episode_poster_url_small" : "http://gomiso.com/uploads/BAhbCFsHOgZmIigyMDEyLzExLzE5LzA2LzM3LzUxLzg5Mi~DrW5kaWNlLmpwZ1sHOgZlOghqcGdbCDoGcDoKdGh1bWIiDTEyNXg3NSNu.jpg",
"episode_season_num" : 2,
"episode_title" : "Two Hats",
@timothy1ee
timothy1ee / gist:1161664
Created August 22, 2011 04:35
Vendor tasklist notes
Basic demo application
======================
- Build a sample project/workspace
- Add all commonly used iOS libraries
Sample Folder structure
=======================
- demo_project
- demo_project.pbxproj
- multiple targets