Skip to content

Instantly share code, notes, and snippets.

View keithelliott's full-sized avatar

Keith Elliott keithelliott

View GitHub Profile
#import "ViewController.h"
#import "FoursquareAuthentication.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
#pragma mark - Web view delegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if([request.URL.scheme isEqualToString:@"ios-app"]){
// 8. get the url and check for the access token in the callback url
NSString *URLString = [[request URL] absoluteString];
if ([URLString rangeOfString:@"access_token="].location != NSNotFound) {
// 9. Store the access token in the user defaults
NSString *accessToken = [[URLString componentsSeparatedByString:@"="] lastObject];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
#import "FoursquareAuthentication.h"
// 5. setup some helpers so we don't have to hard-code everything
#define FOURSQUARE_AUTHENTICATE_URL @"https://foursquare.com/oauth2/authorize"
#define FOURSQUARE_CLIENT_ID @"YOUR CLIENT ID"
#define FOURSQUARE_CLIENT_SECRET @"YOUR CLIENT SECRET"
#define FOURSQUARE_REDIRECT_URI @"ios-app://redirect"
@interface FoursquareAuthentication ()
@keithelliott
keithelliott / ChooserViewController.h
Created March 2, 2013 16:33
ChooserViewController
#import <UIKit/UIKit.h>
@class WineUtils;
static int const COMPONENTS_IN_REGION = 2;
static int const COMPONENTS_DEFAULT = 1;
typedef enum ChooserUIEnum{
CTYear,
CTRegion,
CTType
@keithelliott
keithelliott / AddRatingViewController.h
Created March 2, 2013 16:31
AddRatingController - view controller for adding a rating
#import <UIKit/UIKit.h>
@class ChooserViewController;
static int const HIGHEST_RATING = 5;
static int const LOWEST_RATING = 1;
static int const CHOOSER_VIEW = 5000;
@keithelliott
keithelliott / WineUtils.h
Created March 2, 2013 16:27
Utils for Wine sample app
static int const CURRENT_YEAR = 2013;
static int const MAX_YEARS = 20;
@interface WineUtils : NSObject
@property(nonatomic, strong) NSDictionary *wineRegionsDict;
@property (nonatomic, strong) NSArray *wineTypes;
@property (nonatomic, strong) NSArray *wineYears;
- (NSArray *)wineRegionsForCountry:(NSString *)country;
@keithelliott
keithelliott / timeoutexample.js
Created August 14, 2012 14:29
using setTimeout
// When using setTimeout, use one of the following patterns
//ex1
var fn1 = function(){
// do something
};
setTimeout(fn1, 0);
//ex2
@keithelliott
keithelliott / statements.js
Created August 14, 2012 14:16
Example of JavaScript statements
// End each statement with a semicolon
// example 1 - var that is assigned to a function
var foo = function(){
// do some stuff
}; // semicolon required to end statement
// Example 2 - no semicolon needed
@keithelliott
keithelliott / global-example.js
Created August 13, 2012 15:59
Deal with Global Functions and Properties
// Example 1: Wrapping function and passing in global variables
// self-executing function that passes in the global context via this when the file loads
(function myGlobalExample(global){
return {
testFn: function(){
var doIt = global.doItTimes(5);
return doIt;
}
};
@keithelliott
keithelliott / example_namespace_usage.js
Created July 25, 2012 19:26
use a javascript namespace
//uses the following syntax to create an object with private properties
// and functions. You expose the properties and functions you need publicly in the
// return object.... The immediate function allows us to have private scope for
// certain things
// Create a new namespace
CHATHAM.namespace('CHATHAM.utils.gridmgr');
CHATHAM.utils.gridmgr = (function(){