Skip to content

Instantly share code, notes, and snippets.

@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:ab8ccdb0640f252a0528
Created March 21, 2015 22:08
Insertion and deletion into a binary search tree in objective c
#import
@interface Node : NSObject{
Node *left;
Node *right;
NSObject *data;
}
@property (nonatomic, strong) Node *left;
@property (nonatomic, strong) Node *right;
@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
@kmdarshan
kmdarshan / autorelease_pool1
Last active August 29, 2015 14:21
Autorelease pool
// without using auto release pools
NSMutableArray *temporaryArrayForPairs = [NSMutableArray new];
for (int i=0; i<500000; i++) {
Pair *pair = [Pair new];
pair.grandParent = @"darshan was here";
[temporaryArrayForPairs addObject:pair];
}
@kmdarshan
kmdarshan / autorelease_pool2
Last active August 29, 2015 14:21
Autorelease pool2
// Using auto release pools
@autoreleasepool {
NSMutableArray *temporaryArrayForPairs = [NSMutableArray new];
for (int i=0; i<500000; i++) {
Pair *pair = [Pair new];
pair.grandParent = @"darshan was here";
[temporaryArrayForPairs addObject:pair];
}
}
@kmdarshan
kmdarshan / blocks.m
Last active August 29, 2015 14:21
Playing around with Blocks in Objective-C
@interface Pair : NSObject
@property (nonatomic, copy) void (^blockAsProperty)(int val);
+(void) displayBlock:(void(^)(int param))blockAsMethodParameter;
@end
@implementation Pair
+(void) displayBlock:(void(^)(int param)) blockAsMethodParameter{
blockAsMethodParameter(10);
}
@end
@kmdarshan
kmdarshan / dispatch_async_blocks.m
Last active August 29, 2015 14:21
Using dispatch queues instead of locks and synchronization blocks
// feeder methods to test
self.counter = 10;
[self testThreads];
[self serialQs];
-(void) serialQs {
dispatch_queue_t dispatchQueue = dispatch_queue_create("com.darshan.learn.dispatch", DISPATCH_QUEUE_SERIAL);
__weak typeof (self) weakSelf = self;
@kmdarshan
kmdarshan / performance.html
Created May 28, 2015 00:03
Performance for a given page
The following script calculates how much time to load a page since the most recent navigation.
<html>
<head>
<script type="text/javascript">
function onLoad() {
var now = new Date().getTime();
var page_load_time = now - performance.timing.navigationStart;
alert("User-perceived page loading time: " + page_load_time);
}