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 / JoinNSArrayIntoNSString.m
Created February 10, 2012 06:55
How to join NSArray elements into an NSString?
NSArray *args = [[NSArray alloc] initWithObjects:@"Apple", @"iOS", @"5.1", nil];
NSLog(@"%@", [args componentsJoinedByString:@" "]);
@hanksudo
hanksudo / UIBarButtonItenTextAttribute.m
Created March 13, 2012 05:53
UIBarButtonItenTextAttribute
[[UIBarButtonItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"Helvetica Bold" size:13.0], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
@hanksudo
hanksudo / OpenInSafari.m
Created March 15, 2012 07:19
[iOS Dev] Implement "Open in Safari"
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.apple.com"]];
@hanksudo
hanksudo / UITextFieldChangedEvent.m
Created March 15, 2012 09:18
UITextField Changed Event
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(textFieldChanged:)
name:UITextFieldTextDidChangeNotification
object:toTextField];
@hanksudo
hanksudo / ParseJSONfromFile.m
Created April 3, 2012 10:46
Parse JSON from file.
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"];
NSString *jsonString = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [self parseJSON:jsonData];
}
@hanksudo
hanksudo / EscapeURLfor.m
Created April 30, 2012 08:28
Escape URL for iOS5
- (NSString *)escape:(NSString *)text
{
return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge CFStringRef)text,
NULL,
CFSTR("!*'();:@&=+$,/?%#[]"),
CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
}
@hanksudo
hanksudo / repackSystemImage.sh
Last active October 4, 2015 22:27
[Android] repack System Image
#!/usr/bin/env bash
out/host/linux-x86/bin/mkyaffs2image -f out/target/product/generic/system out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img
out/host/linux-x86/bin/acp -fpt out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/generic/system.img
@hanksudo
hanksudo / SortNSArrayNumberLast.m
Created May 23, 2012 04:34
Sort NSArray using sortedArrayUsingComparator, number last.
- (NSArray *)sortArrayNumberLast:(NSArray *)arr {
return [arr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSString *s1 = [obj1 substringToIndex:1];
NSString *s2 = [obj2 substringToIndex:1];
if ([s1 rangeOfCharacterFromSet:[NSCharacterSet decimalDigitCharacterSet]].location == [s2 rangeOfCharacterFromSet:[NSCharacterSet decimalDigitCharacterSet]].location) {
return [obj1 compare:obj2];
} else {
if ([s1 rangeOfCharacterFromSet:[NSCharacterSet decimalDigitCharacterSet]].location == NSNotFound) {
@hanksudo
hanksudo / Bash.sublime-build
Created July 27, 2012 10:28 — forked from typeoneerror/Bash.sublime-build
Bash build system for running currently open script in Sublime Text 2/3
{
"cmd" : ["/bin/sh", "$file"],
"selector" : "source.sh"
}
@hanksudo
hanksudo / fixpip.sh
Created August 1, 2012 04:08
fix Mac Mountain Lion lib pip
wget http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py
sudo easy_install -U pip
ln -s /Library/Frameworks/Python.framework/Versions/2.7/bin/pip /usr/local/bin/