Skip to content

Instantly share code, notes, and snippets.

View kirang89's full-sized avatar

Kiran Gangadharan kirang89

View GitHub Profile
@kirang89
kirang89 / PushSegueStoryboardExample.m
Created May 30, 2014 07:45
Doing a push segue using StoryBoard instance instead of the prepareForSegue method
UIStoryboard * myStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
DestinationViewController *dVC = [myStoryboard instantiateViewControllerWithIdentifier:@"storyboard_id_for_dVC"];
[self.navigationController pushViewController:urlVC animated:YES];
@kirang89
kirang89 / getFontNames.m
Created May 28, 2014 00:53
Snippet to get all font names available to XCode
-(void)dumpAllFonts {
for (NSString *familyName in [UIFont familyNames]) {
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(@"%@", fontName);
}
}
}
@kirang89
kirang89 / SetRootVC.m
Created May 19, 2014 16:27
Init snippet for setting the root view controller
- (BOOL) application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.viewController = [[ViewController alloc] initWithNibName:nil
bundle:nil];
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
/* Make our view controller the root view controller */
self.window.rootViewController = self.viewController;
@kirang89
kirang89 / ImageTypeEx.m
Created May 18, 2014 14:59
Determine the type of image data based on the first couple bytes of the header
static inline NSPUIImageType NSPUIImageTypeFromData(NSData *imageData) {
if (imageData.length > 4) {
const unsigned char * bytes = [imageData bytes];
if (bytes[0] == 0xff &&
bytes[1] == 0xd8 &&
bytes[2] == 0xff)
{
return NSPUIImageType_JPEG;
}
@kirang89
kirang89 / urlTracking.m
Created May 18, 2014 14:57
Injecting analytics into outgoing links by overriding AppDelegate -openURL::
-(BOOL)openURL:(NSURL *)url{
if ([[url scheme] hasPrefix:@"http"]) {
[[GAI sharedInstance].defaultTracker sendView:[url absoluteString]];
}
return [super openURL:url];
}
@kirang89
kirang89 / fbShareExample.m
Last active August 29, 2015 14:01
Implementing FB sharing in iOS
#
# Make sure to add Social.Framework to the list of dependencies
#
#import "Social/Social.h"
#import "Accounts/Accounts.h"
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
@kirang89
kirang89 / pollingExampleSnippet.m
Last active August 29, 2015 14:01
Polling Example in iOS
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(pollingMethod)
userInfo:nil
repeats:YES];
-(void)pollingMethod {
NSLog(@"Polling method called");
}
@kirang89
kirang89 / error_resolution.md
Last active August 29, 2015 14:00
Bypassing “clang: error: unknown argument”

To Bypass the clang error:

clang: error: unknown argument: ‘-mno-fused-madd’ [-Wunused-command-line-argument-hard-error-in-future]

while pip installing some package, run the following command before pip install:

export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future" 

pip install -r requirements.txt
@kirang89
kirang89 / status_codes_reasons.txt
Created April 23, 2014 21:14
HTTP Status Codes and Reasons
100: Continue
101: Switching Protocols
200: OK
201: Created
202: Accepted
203: Non-Authoritative Information
204: No Content
205: Reset Content
206: Partial Content
300: Multiple Choices
@kirang89
kirang89 / pg_optimal_settings.md
Last active August 29, 2015 14:00
Optimal Settings for Postgres

###Optimal Settings for Postgres

log_destination = 'csvlog'

log_directory = 'pg_log'

logging_collector = on (rotates files)

log_filename = 'postgres-%Y-%m-%d_%H%M%S'