Skip to content

Instantly share code, notes, and snippets.

@kmdarshan
kmdarshan / gist:498c76a026948f27a84d
Created February 3, 2015 03:01
Pattern searching
//
// main.m
// chrono
//
// Created by Darshan Katrumane on 2/2/15.
// Copyright (c) 2015 Darshan Katrumane. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@kmdarshan
kmdarshan / gist:02b0b662eb2e1012777d
Last active August 29, 2015 14:16
Recursively printing all subviews within a view given a tag
- (void)printSubViews:(UIView *)view withTag:(NSInteger)tag
{
if (view == nil) {
return;
}
if ( [view tag] == tag) {
NSLog(@"%@", view);
return;
}
for (UIView *subview in [view subviews])
// interface
@interface MaxSubArray : NSObject
@end
// extension
@interface MaxSubArray()
@end
@kmdarshan
kmdarshan / gist:fec1374b5c160abf51be
Created March 9, 2015 04:42
Checking for null objects
@implementation RRUser
@synthesize email, name, facebookId, userId, sessionToken, imageUrl;
-(void) parseResponse:(NSDictionary*) data {
// this is a better way to test, if the class responds to a selector
// then go ahead and read from it
if([[data objectForKey:@"email"] respondsToSelector:@selector(length)]) {
self.email = [data objectForKey:@"email"];
}
if([[data objectForKey:@"name"] respondsToSelector:@selector(length)]) {
self.name = [data objectForKey:@"name"];
{
id: "54c58d22e",
dateCreated: "2015-01-26T00:41:06.687Z",
email: "poon@gmail.com",
facebookId: "490325",
imageUrl: "https://graph.facebook.com/1015/picture?width=50&height=50",
iosDeviceToken: "75b61936b004381d9aab643c5",
lastUpdated: "2015-03-08T21:07:00.421Z",
name: null,
sessionToken: "dba99343-368e-47a8-9198"
// change the color of the navigation bar
[[UINavigationBar appearanceWhenContainedIn:[UINavigationController class], nil] setBarTintColor:[RRHelper appBlue]];
// change the tint color of the navigation bar
[[UINavigationBar appearanceWhenContainedIn:[UINavigationController class], nil] setTintColor:[UIColor whiteColor]];
// change the title text attributes
[[UINavigationBar appearanceWhenContainedIn:[UINavigationController class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, [UIFont fontWithName:kFontRegular size:18.0], NSFontAttributeName, @0.5, NSKernAttributeName, nil]];
// change the bar button item properties
@kmdarshan
kmdarshan / gist:b9f962c5a41bdc09ba0b
Last active August 29, 2015 14:17
Printing level tree order in objective c
//
// Tree.h
// learnObjectiveC
//
// Created by kmd on 3/3/15.
// Copyright (c) 2015 Happy Days. All rights reserved.
//
#import <Foundation/Foundation.h>
@kmdarshan
kmdarshan / gist:1d82494978d298e8cd1e
Created March 20, 2015 04:10
Queue in objective c
//
// RRQueue.h
// learnObjectiveC
//
// Created by darshan on 3/19/15.
// Copyright (c) 2015 Happy Days. All rights reserved.
//
#import <Foundation/Foundation.h>
@kmdarshan
kmdarshan / gist:bd1657c1767784df8e35
Last active August 29, 2015 14:17
subqueries VS joins
In Mysql, if your using a subquery to update a table, it will give you an error.
e.x. In the below query your basically trying to update and query the table at the same time. This would not be possible in Mysql.
[code language="text"]
UPDATE items ci SET ci.`c_id` = 27
WHERE ci.`ID` IN (
SELECT c.`ID`
FROM orders f, items c
WHERE c.`orderID` = f.`orderID` LIMIT 100;
@kmdarshan
kmdarshan / gist:4fa27d7429412833e9f1
Last active August 29, 2015 14:20
UIDynamicKit : Most commonly used animation behaviors
@interface RRHomeViewController ()
{
UIButton *logoutButton;
UIView *testAnimateView;
}
@property (nonatomic, strong) UIDynamicAnimator *animator;
@property (nonatomic, strong) UIDynamicItemBehavior *linearVelocity;
@end
@implementation RRHomeViewController