Skip to content

Instantly share code, notes, and snippets.

@kmdarshan
kmdarshan / gist:6330926
Created August 24, 2013 23:12
Fibonacci sequence [ iterative/recursive/cached] with timers.
package programs;
public class Fibonacci {
public static int fibrecursive(int n) {
if(n<=1){
return n;
}
return fibrecursive(n-1)+fibrecursive(n-2);
}
@kmdarshan
kmdarshan / gist:6337103
Created August 26, 2013 00:10
Removing duplicates in a linked list. Comparison using different methods.
package linkedlist;
import java.util.HashSet;
import java.util.Iterator;
class Node {
int data;
Node next;
Node(int data){
this.data = data;
this.next = null;
@kmdarshan
kmdarshan / gist:6719785
Created September 26, 2013 20:04
//Given a sorted list that has been transposed (that is, a portion has been removed from one end and attached to the other), write a function to determine if a given number is present in the list. //567812 -> (1) true 1 2 3 4 5 6
class Search {
public static boolean binsearch(int [] a, int value){
int low =0;
int high = arr.length - 1;
int mid = 0;
while(low <= high) { // binsearch(a, 1, 4, 4)
mid = (low+high) / 2; // 4
if(a[mid] > value) {
high = mid - 1;
@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])
@kmdarshan
kmdarshan / gist:7d2b66d12bf013b28480
Created February 28, 2015 23:21
Circular linked list in Objective C
//
// CircularLinkedList.h
// learnObjectiveC
//
// Created by kmd on 2/28/15.
// Copyright (c) 2015 Happy Days. All rights reserved.
//
#import <Foundation/Foundation.h>
// 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