Skip to content

Instantly share code, notes, and snippets.

View hanksudo's full-sized avatar
:octocat:
Follow your passion.

Hank Wang hanksudo

:octocat:
Follow your passion.
View GitHub Profile
@hanksudo
hanksudo / RetryAlertForm.m
Created February 9, 2011 08:59
Retry Alert form, need to set UIAlertViewDelegate protocols
- (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];
}
@hanksudo
hanksudo / ConnectionTestAppDelegate.h
Created February 9, 2011 09:35
Test URL connection
//
// ConnectionTestAppDelegate.h
// ConnectionTest
//
// Created by Hank Wang on 2011/2/9.
//
#import <UIKit/UIKit.h>
@interface ConnectionTestAppDelegate : NSObject <UIApplicationDelegate, UIAlertViewDelegate> {
@hanksudo
hanksudo / ActionSheetViewController.h
Created February 11, 2011 10:31
Simple Snippet to implement UIActionSheet
#import <UIKit/UIKit.h>
@interface UntitledViewController : UIViewController <UIActionSheetDelegate> {
}
- (IBAction)showActionSheet:(id)sender;
@end
@hanksudo
hanksudo / loadImageFromURL.m
Created March 8, 2011 04:29
Load Image to UIImage from URL String
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];
@hanksudo
hanksudo / NSDateConverter.m
Created March 9, 2011 07:08
NSDate, NSString conversion and get TimeZone
// 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]];
@hanksudo
hanksudo / CoreDataUpdateRecord.m
Created March 15, 2011 04:20
CoreData Update Record Sample
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];
@hanksudo
hanksudo / fetchData.py
Created March 25, 2011 08:44
urllib POST data
import urllib2, urllib
base_url = 'http://login.domain.com'
params = {'username':'hank',
'password':'hank',
}
data = urllib.urlencode(params)
req = urllib2.Request(base_url, data)
@hanksudo
hanksudo / template_extras.py
Created April 18, 2011 06:44
Django custom filter : replace
# shiftv templatetags
# -*- coding: utf-8 -*-
import re
from django import template
register = template.Library()
@register.filter
@hanksudo
hanksudo / vimeoid2url.php
Created May 16, 2011 10:21
Get Vimeo source url
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;
}
@hanksudo
hanksudo / GetTweetId.py
Created May 19, 2011 08:52
Regex : Get Tweet Id by tweet
import re
s = 'https://twitter.com/#!/twitter/status/70943739882913792'
print re.search('/status/(\d+)', s).group(1)