Skip to content

Instantly share code, notes, and snippets.

View pratikshabhisikar's full-sized avatar

Pratiksha Bhisikar pratikshabhisikar

View GitHub Profile
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian setLocale:[NSLocale currentLocale]];
[gregorian setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
NSDate *now = [NSDate date]; // This is current date or the end date for the graph.
NSLog(@"Now: %@", now);
NSDateComponents *currentDateComponents = [gregorian components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:now];
NSDateComponents *startDateComponents = [[NSDateComponents alloc] init];
@pratikshabhisikar
pratikshabhisikar / gist:1992680
Created March 7, 2012 11:46
Holy Message to all Men
Man O Man
When without money, eats wild vegetables at home
When has money, eats same wild vegetables in fine restaurant.
When without money, rides bicycle;
When has money, rides exercise machine.
When without money, walks to earn food
When has money, walks to lose the fat.
@pratikshabhisikar
pratikshabhisikar / gist:1957579
Created March 2, 2012 10:29
Converting Base Pointer to Derived Pointer
NSString *base = [[NSString alloc] initWithString:@"Base"];
NSLog(@"Base pointer is instantiated with type: %@", [base class]);
// NSMutableString is derived from NSString class.
NSMutableString *derived = [NSMutableString stringWithString:@"Derived"];
NSLog(@"Derived pointer is instantiated with type: %@", [derived class]);
// Converting Base to Derived:-
base = derived;
@pratikshabhisikar
pratikshabhisikar / gist:1947756
Created March 1, 2012 06:23
Don't chat while working
One FRIEND WAS chatting with a female - Online chat.
(Background both are s/w engineers by the way and both work for real big MNC's)
Hero : Hey...GM (Good Morning)... How's u doing today?
Female: VGM...Day is going good and it got better having found u on chat
Hero : wow...am honoured, u know what, my day starts only when I find you on Chat
@pratikshabhisikar
pratikshabhisikar / gist:1932018
Created February 28, 2012 11:26
Fetch Google Places
[googlePlaces fetchWithCompletionHandler:^(NSMutableSet *fetchedPlaces, NSError *error){
if (fetchedPlaces) {
places = [[NSMutableArray alloc] initWithArray:[fetchedPlaces allObjects]];
[self.tableView reloadData];
}else {
if (error) {
// Optionally display error here.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
NSString *jsonString = @"{\
\"posts\" : [\
{\
\"post\" : {\
\"description\" : \"The latest news from the Joomla! Team\",\
\"id\" : \"1\",\
\"title\" : \"Latest\"\
}\
},\
{\
NSRange searchStringRange = [textView rangeOfString:@"string to search goes here" options:NSCaseInsensitiveSearch];
if (searchStringRange.location != NSNotFound) {
// Got the search string.
NSString *searchStringInTextView = [textView substringWithRange:searchStringRange];
NSLog(@"The search string is: %@", searchStringInTextView);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",dic_txt);
static NSString *CustomCellIdentifier = @"CustomCellIdentifier ";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell=self.tvcell;
self.tvcell=nil;
@pratikshabhisikar
pratikshabhisikar / gist:1854333
Created February 17, 2012 16:50
Blocks Error
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
completionHandler(iTunesURL, NO, error);
}
AppStoreConnectionHandler *appStoreConnection = [[AppStoreConnectionHandler alloc] init];
[appStoreConnection initiateConnectionForAppURL:[NSURL URLWithString:appURL] withCompletionBlock:^(NSURL *appURL, BOOL finished, NSError *error){
if (finished) {
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:appURL];
if (canOpenURL) {
[[UIApplication sharedApplication] openURL:appURL];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"Application cannot open the URL" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}