Skip to content

Instantly share code, notes, and snippets.

View pratikshabhisikar's full-sized avatar

Pratiksha Bhisikar pratikshabhisikar

View GitHub Profile
NSString *date = nil;
NSScanner *scanner = [NSScanner scannerWithString:@"/Date(1312603200000-0400)/"];
while ([scanner isAtEnd] == NO) {
[scanner scanUpToString:@"(" intoString:NULL];
[scanner setScanLocation:[scanner scanLocation] + 1];
[scanner scanUpToString:@")" intoString:&date];
break;
}
@pratikshabhisikar
pratikshabhisikar / gist:1133705
Created August 9, 2011 10:10
Add new cell to table
// Get number of rows in your table.
NSUInteger existingRows = ...;
// Create the index path of new cell to be added.
NSIndexPath *newCellIndexPath = [NSIndexPath indexPathForRow:existingRows inSection:0];
// Update the datasource model...
// Add the new cell to table.
[self.myTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newCellIndexPath] withRowAnimation:UITableViewRowAnimationFade];
@pratikshabhisikar
pratikshabhisikar / gist:1136244
Created August 10, 2011 06:26
Dismissing UIView manually
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[self.view removeFromSuperview];
}
-(void) dismiss {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
@pratikshabhisikar
pratikshabhisikar / gist:1139472
Created August 11, 2011 11:57
Using CSS in HTML
<html>
<head>
<title>Recipe</title>
<link href='style.css' rel='stylesheet' type='text/css' />
</head>
<body>
<div style='width: 320px;' align='center'>
<div class='stats' >
<div class='recipe_title' align='center'>
<span class='title_brace'>{</span><span>Title</span><span class='title_brace'>}</span>
@pratikshabhisikar
pratikshabhisikar / gist:1141614
Created August 12, 2011 07:04
Removing Objects from an array from another array
NSMutableArray *parentArray = [[NSMutableArray alloc] initWithCapacity:5];
for (int i = 0; i < 5; i++) {
[parentArray addObject:[NSNumber numberWithInt:i]];
}
NSMutableArray *childArray = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInt:0], [NSNumber numberWithInt:1], nil];
[parentArray removeObjectsInArray:childArray];
NSLog(@"%@", parentArray);
@pratikshabhisikar
pratikshabhisikar / gist:1141833
Created August 12, 2011 10:37
Saving username and password in userdefaults
#define USERNAME_KEY @"username"
#define PASSWORD_KEY @"password"
-(void) saveUser:(NSString *) username andPassword:(NSString *) password {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
// Save the username.
[userDefaults setObject:username forKey:USERNAME_KEY];
[userDefaults synchronize];
// Save the password.
@try {
if (versionOk == YES)
{
NSLog(@"Before Saving - Username: %@ and Password: %@", username.text, password.text);
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:username.text forKey:@"username"];
@pratikshabhisikar
pratikshabhisikar / gist:1141920
Created August 12, 2011 12:05
Checking if user already exists
if (indexPath.row == 4) {
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];
if (username && password) {
// User already exists. Go Directly to ever note view controller.
}else {
// User has not logged in. Go to ever note login view controller.
Evernotelogin *evernoteView = [[Evernotelogin alloc] initWithNibName:@"Evernotelogin"
@interface Dog : NSObject {
}
@property (nonatomic, assign) id<DogDelegate> delegate;
-(void) bark;
@end
#import "Dog.h"
@implementation Dog
@synthesize delegate;
-(void) bark {
if(self.delegate != nil && [self.delegate respondsToSelector:@selector(dogWillStartBarking:)]) {
[self.delegate dogWillStartBarking:self];
}