Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Follow your passion.

Hank Wang hanksudo

:octocat:
Follow your passion.
  • Taipei, Taiwan & Tokyo, Japan
View GitHub Profile
@hanksudo
hanksudo / RetryAlertForm.m
Created Feb 9, 2011
Retry Alert form, need to set UIAlertViewDelegate protocols
View RetryAlertForm.m
- (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];
}
View ConnectionTestAppDelegate.h
//
// 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 Feb 11, 2011
Simple Snippet to implement UIActionSheet
View ActionSheetViewController.h
#import <UIKit/UIKit.h>
@interface UntitledViewController : UIViewController <UIActionSheetDelegate> {
}
- (IBAction)showActionSheet:(id)sender;
@end
@hanksudo
hanksudo / loadImageFromURL.m
Created Mar 8, 2011
Load Image to UIImage from URL String
View loadImageFromURL.m
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 Mar 9, 2011
NSDate, NSString conversion and get TimeZone
View NSDateConverter.m
// 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 Mar 15, 2011
CoreData Update Record Sample
View CoreDataUpdateRecord.m
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 Mar 25, 2011
urllib POST data
View fetchData.py
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 Apr 18, 2011
Django custom filter : replace
View template_extras.py
# shiftv templatetags
# -*- coding: utf-8 -*-
import re
from django import template
register = template.Library()
@register.filter
@hanksudo
hanksudo / vimeoid2url.php
Created May 16, 2011
Get Vimeo source url
View vimeoid2url.php
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
Regex : Get Tweet Id by tweet
View GetTweetId.py
import re
s = 'https://twitter.com/#!/twitter/status/70943739882913792'
print re.search('/status/(\d+)', s).group(1)