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 / unique.js
Created June 2, 2011 09:10
Remove Duplicate elements from array, discover from
Array.prototype.unique = function () {
var arrVal = this;
var uniqueArr = [];
for (var i = arrVal.length; i--; ) {
var val = arrVal[i];
if ($.inArray(val, uniqueArr) === -1) {
uniqueArr.unshift(val);
}
}
return uniqueArr;
@hanksudo
hanksudo / fetch_info.py
Created June 28, 2011 06:53
Fetch data from SC2 battle.net then save to Google spreadsheet - fetch_info
# fetch info
# -*- coding: utf-8 -*-
import urllib2, re
from BeautifulSoup import BeautifulSoup
def fetch_info(url):
data = urllib2.urlopen(url).read()
soup = BeautifulSoup(data)
@hanksudo
hanksudo / selectRandomElement.js
Created June 30, 2011 08:56
Select a random element
(function($){
var random = 0;
$.expr[':'].random = function(a, i, m, r) {
if (i == 0) {
random = Math.floor(Math.random() * r.length);
}
return i == random;
};
@hanksudo
hanksudo / repeat_word.js
Created September 28, 2011 11:25
A function reutrn repeat_words
function repeat_word(str, n) {
return new Array(n+1).join(str);
}
@hanksudo
hanksudo / repeat_words_for.js
Created September 28, 2011 11:31
A function reutrn repeat_words
function repeat_word(str, n) {
var s = ''
for (i=0; i<n; i++) {
s += str;
}
return s;
}
@hanksudo
hanksudo / is_palindrome.js
Created September 28, 2011 14:51
Detect string is_palindrome or not
function is_palindrome(str) {
l = str.split('');
for (i=0; i<l.length; i++) {
if(l[i] != l[l.length-1-i]) {
return false;
}
}
return true;
}
@hanksudo
hanksudo / xmltest.erl
Created October 20, 2011 06:40
simple sample to parse XML by xmerl
%%% xmltest.erl
%%%
%%% @author Hank Wang <drapho@gmail.com>
%%%
%%% @doc simple sample to parse XML by xmerl
%%%
-module(xmltest).
-include_lib("xmerl/include/xmerl.hrl").
@hanksudo
hanksudo / NSUserDefaultsSample.m
Created February 1, 2012 09:43
NSUserDefaults - save/laod/clear simple rample
// 定義名稱 define key
#define kIsActive @"isActive"
#define kUserName @"userName"
// 讀取資料
-(void)loadInfo {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"Name : %@", [defaults stringForKey:kUserName]);
NSLog(@"isActive : %@", ([defaults boolForKey:kIsActive] ? @"YES" : @"NO"));
}
@hanksudo
hanksudo / parseQueryString.m
Created February 6, 2012 03:50
Parse query string into dictionary
- (NSDictionary *)parseQueryString:(NSString *)query {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:6];
NSArray *pairs = [query componentsSeparatedByString:@"&"];
for (NSString *pair in pairs) {
NSArray *elements = [pair componentsSeparatedByString:@"="];
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[dict setObject:val forKey:key];
@hanksudo
hanksudo / DisabledUIWebViewBounce.m
Created February 10, 2012 03:32
Disable UIWebView "bouncing" vertically
for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;