This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)handleError:(NSError *)error { | |
NSString *errorMessage = [error localizedDescription]; | |
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Message" | |
message:errorMessage | |
delegate:self | |
cancelButtonTitle:@"Cancel" | |
otherButtonTitles:@"Retry", nil]; | |
[alertView show]; | |
[alertView release]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ConnectionTestAppDelegate.h | |
// ConnectionTest | |
// | |
// Created by Hank Wang on 2011/2/9. | |
// | |
#import <UIKit/UIKit.h> | |
@interface ConnectionTestAppDelegate : NSObject <UIApplicationDelegate, UIAlertViewDelegate> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UntitledViewController : UIViewController <UIActionSheetDelegate> { | |
} | |
- (IBAction)showActionSheet:(id)sender; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *urlString = [NSString stringWithString:@"http://teddymaulana.files.wordpress.com/2009/11/iu1.jpg"]; | |
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]]; | |
UIImageView *imgView = [[UIImageView alloc] initWithImage:image]; | |
CGRect frame = CGRectMake(75, 75, 160, 230); | |
[imgView setFrame:frame]; | |
[imgView setContentMode: UIViewContentModeScaleAspectFit]; | |
[self.view addSubview:imgView]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get TimeZone | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"Z"]; | |
NSString *tz = [dateFormatter stringFromDate:[NSDate date]]; | |
[dateFormatter release]; | |
// Convert NSDate to NSString | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | |
NSString *strDate = [dateFormatter stringFromDate:[NSDate date]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Statistic *statistic = nil; | |
NSFetchRequest *request = [[NSFetchRequest alloc] init]; | |
request.entity = [NSEntityDescription entityForName:@"Statistic" inManagedObjectContext:context]; | |
request.predicate = [NSPredicate predicateWithFormat:@"level = %i", _level]; | |
statistic = [[context executeFetchRequest:request error:nil] lastObject]; | |
[request release]; | |
float currentHighScore = [statistic.score floatValue]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2, urllib | |
base_url = 'http://login.domain.com' | |
params = {'username':'hank', | |
'password':'hank', | |
} | |
data = urllib.urlencode(params) | |
req = urllib2.Request(base_url, data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# shiftv templatetags | |
# -*- coding: utf-8 -*- | |
import re | |
from django import template | |
register = template.Library() | |
@register.filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vimeoid2url($id) { | |
$xmlurl = "http://www.vimeo.com/moogaloop/load/clip:{$id}"; | |
$videoxml = file_get_contents($xmlurl); | |
preg_match('|<request_signature>(.*)</request_signature>|i',$videoxml,$sig); | |
preg_match('|<request_signature_expires>(.*)</request_signature_expires>|i',$videoxml,$sigexp); | |
$url = "http://www.vimeo.com/moogaloop/play/clip:{$id}/{$sig[1]}/{$sigexp[1]}/?q=sd"; | |
return $url; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
s = 'https://twitter.com/#!/twitter/status/70943739882913792' | |
print re.search('/status/(\d+)', s).group(1) |
OlderNewer