Skip to content

Instantly share code, notes, and snippets.

@aug2uag
aug2uag / gist:8214251
Last active January 1, 2016 23:08
Meetup API Login iOS
#import "LoginViewController.h"
#import "Global.h"
#import "MeetupTopic.h"
#import "UserAuthenticated.h"
@interface LoginViewController () <UIWebViewDelegate>
@property (strong, nonatomic) UIWebView* webView;
@property (strong, nonatomic) NSNumber* userId;
@end
@aug2uag
aug2uag / gist:8214700
Created January 2, 2014 03:35
Google OAuth
- (void)goGoogle
{
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.delegate = self;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.clientID = GOOGLE_CLIENTID;
signIn.scopes = [NSArray arrayWithObjects:kGTLAuthScopePlusLogin,nil];
signIn.actions = [NSArray arrayWithObjects:@"http://schemas.google.com/ListenActivity",nil];
[signIn authenticate];
}
@aug2uag
aug2uag / gist:8244608
Created January 3, 2014 19:21
move keyboard delegate for UITextView
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[self animateTextView:textView up: YES];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
[self animateTextView:textView up:NO];
}
@aug2uag
aug2uag / gist:8307630
Last active January 2, 2016 13:09
Programmatically instantiate ViewController in AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor clearColor];
ViewController *viewController = [[ViewController alloc] init];
self.window.rootViewController = viewController;
@aug2uag
aug2uag / gist:8378475
Created January 11, 2014 23:41
ACAccountStore Twitter
ACAccountStore *store = [[ACAccountStore alloc] init]; // Long-lived
ACAccountType *twitterType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[store requestAccessToAccountsWithType:twitterType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
// Access has been granted, now we can access the accounts
// Remember that twitterType was instantiated above
NSArray *twitterAccounts = [store accountsWithAccountType:twitterType];
// If there are no accounts, we need to pop up an alert
if(twitterAccounts != nil && [twitterAccounts count] == 0) {
@aug2uag
aug2uag / gist:8425615
Last active January 3, 2016 06:49
Google v3 reverse geocoding api
// on button click, get and display user location to view
- (void)cityStateFinder
{
NSLog(@"%s [Line %d]", __PRETTY_FUNCTION__, __LINE__);
// init location
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
@aug2uag
aug2uag / gist:8431827
Created January 15, 2014 06:38
Cocoa random string generator
// Rex Fatahi Jan 2014
// use as category for NSString*
+ (NSString *)randomNameGenerator:(NSInteger)characterLength
{
NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
NSMutableString *randomString = [NSMutableString stringWithCapacity:characterLength];
for (int i = 0; i < characterLength; i++) {
[randomString appendFormat: @"%C", [letters characterAtIndex: arc4random() % [letters length]]];
@aug2uag
aug2uag / gist:8432061
Created January 15, 2014 07:04
Random NSNumber in range
+ (NSNumber *)randomNumberFromRangeMax:(NSInteger)aMax Min:(NSInteger)aMin
{
return [NSNumber numberWithInt:(int)(rand() % (aMax - aMin + 1) + aMin)];
}
@aug2uag
aug2uag / gist:8462729
Created January 16, 2014 20:23
Cocoa textView dismiss on return
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if( [text rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet]].location == NSNotFound ) {
return YES;
}
[self animateTextView:NO];
[textView resignFirstResponder];
return NO;
}
@aug2uag
aug2uag / gist:8464566
Last active January 3, 2016 12:39
NSString is all digits
- (BOOL)isAllDigits:(NSString *)input
{
NSCharacterSet* nonNumbers = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
NSRange r = [input rangeOfCharacterFromSet: nonNumbers];
return r.location == NSNotFound;
}