This file contains hidden or 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
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; |
This file contains hidden or 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
# fetch info | |
# -*- coding: utf-8 -*- | |
import urllib2, re | |
from BeautifulSoup import BeautifulSoup | |
def fetch_info(url): | |
data = urllib2.urlopen(url).read() | |
soup = BeautifulSoup(data) |
This file contains hidden or 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($){ | |
var random = 0; | |
$.expr[':'].random = function(a, i, m, r) { | |
if (i == 0) { | |
random = Math.floor(Math.random() * r.length); | |
} | |
return i == random; | |
}; |
This file contains hidden or 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 repeat_word(str, n) { | |
return new Array(n+1).join(str); | |
} |
This file contains hidden or 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 repeat_word(str, n) { | |
var s = '' | |
for (i=0; i<n; i++) { | |
s += str; | |
} | |
return s; | |
} |
This file contains hidden or 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 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; | |
} |
This file contains hidden or 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
%%% xmltest.erl | |
%%% | |
%%% @author Hank Wang <[email protected]> | |
%%% | |
%%% @doc simple sample to parse XML by xmerl | |
%%% | |
-module(xmltest). | |
-include_lib("xmerl/include/xmerl.hrl"). |
This file contains hidden or 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
// 定義名稱 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")); | |
} |
This file contains hidden or 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
- (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]; |
This file contains hidden or 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
for (id subview in webView.subviews) | |
if ([[subview class] isSubclassOfClass: [UIScrollView class]]) | |
((UIScrollView *)subview).bounces = NO; |