2011年1月30日 星期日

[影片分享] 祝我生日快樂 (Hank Wang covered)



謝謝大家給我的祝福
我的生日願望就是希望大家都能很快樂
不管是大學時一起努力的同學、當兵一起同甘苦的弟兄、平日玩在一起的朋友、一起工作的­同事
雖然大家都為了生活各忙各的很少見面
但是至少我們都曾經為同一個目標努力過
希望未來我們都能過的更好、更快樂
別忘記自己的初衷、努力實現自己的夢想

2011年1月27日 星期四

2011年1月26日 星期三

[Xcode] 常用快捷鍵


Command + Alt + ↑   在.h及.m間切換
Command + Ctrl + Arrow   在.h及.m間切換 (XCode 4)

Command + Shift + E   編輯器視窗最大化

Command + ]   增加縮排

Command + [   減少縮排

ESC   展開所有可能的自動完成列表

Command + Ctrl + ← / →   展開或收起整個function
Command + Alt + ← / →   展開或收起整個function (Xcode 4)

Command + Shift + R   打開Console

Command + Ctrl + Alt + R   清除Console Log

2011年1月25日 星期二

[Python] PythonBee - 冠軍賽- 用嘴巴講出一套好程式



(不負責任翻譯XD)


This is from the final round where our last two contestants competed for a Kindle.
這影片是最後決戰的兩位參賽者

Contestants were not allowed to see their code or have it read back to them in any way. They had to specifically dictate all spelling and punctuation (and tabbing).
參賽者不允許看他們的程式碼或是反悔已經唸過的程式碼, 他們必須唸出所有的標點符號跟空白和Tab

The challenge for the last round was to write a function that would return true if and only if the string passed to it hadmatching sets of parentheses.
最後一回合的比賽, 參賽者必須寫一個程式, 檢查匹配括號的字串, 如果是則return True

[Objective-C] 將NSDictionary新增至NSMutableArray

建立一個words的陣列, 然後建立一個dictionary存入words

Source Code
// 宣告array
NSMutableArray *words = [NSMutableArray array];

// 宣告dictionary
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
   @"Title 01", @"title",
   @"Explain 01", @"explain",
   nil];

// 將dict新增至array裡
[words addObject:dict];

// print出dict中所有資料
for (id key in dict) NSLog(@"key: %@  value: %@", key, [dict objectForKey:key]);

// print出Array中所有資料
for (NSInteger i=0; i < [words count]; i++) NSLog(@"%@", [words objectAtIndex:i]);

// print Array有幾筆資料
NSLog(@"Words count : %i", [words count]);
Result








See Also

NSDictionary Class Reference
NSMutableArray Class Reference

2011年1月21日 星期五

[MySQL] 讓Windows下的MySQL允許使用大寫資料表(Table)名稱

Linux是對大小寫敏感的系統, 也就是同個英文字, 大小寫是不相同的

但是Windows則是不敏感的系統, 會把WINDOWS跟WinDows認成同一個字。

從Linux匯出的資料庫, 若匯入Windows會被自動轉成小寫

解決方法如下

修改
C:\Program Files\MySQL\MySQL Server 5.1\my.ini

加入以下這行

lower_case_table_names = 2

然後重新啟動MySQL Server

接著重新匯入一次資料庫即可

[iPhone] 在iPhone上取得快照 ScreenShot的方法

Image From apple.com

原來iPhone就有內建的ScreenShot功能

1. 先按住圓圓的那顆鍵


2. 按一下待機鍵(右上角那個)

就會把目前畫面存到相簿裡, 非常的方便

2011年1月20日 星期四

[iOS Dev] UITableView換頁時隱藏UITabBar

在換頁的didSelectRowAtIndexPath method中加入:

targetViewController.hidesBottomBarWhenPushed = YES;


Sample
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 UIViewController *targetViewController = [[menuList objectAtIndex: indexPath.row] objectForKey:kViewControllerKey];
 targetViewController.hidesBottomBarWhenPushed = YES;
 [self.navigationController pushViewController:targetViewController animated:YES];
 [targetViewController release];
}


See Also
iLessons iLearned: How to Hide UITabBar

2011年1月17日 星期一

[iOS Dev] Clear all application on iPhone Simulator

iPhone Simulator Application Path
/Users/UserName/Library/Application Support/iPhone Simulator/4.2/Applications

rm -fdr ${HOME}/Library/Application\ Support/iPhone\ Simulator

[Objective-C] NSTimer snippet

[NSTimer
    scheduledTimerWithTimeInterval:2
    target:self
    selector:@selector(doSomething)
    userInfo:nil
    repeats:NO];

NSTimer Class Reference

[iOS Dev] UIAlertView on iPhone App


UIAlertView *alert = [[UIAlertView alloc]
        initWithTitle:@"Title"
        message:@"Message"
        delegate:nil cancelButtonTitle:@"Cancel"
        otherButtonTitles:nil];
 [alert show];
 [alert release];

2011年1月15日 星期六

[Python] 用BeautifulSoup解析HTML範例 - 取出統一發票號碼

[Last Updated: 2013-03-11]

BeautifulSoup用來解析HTML真的很好用, 直接透過pip安裝
$ pip install BeautifulSoup

以下的小範例, 示範如何把 財政部稅務入口網-統一發票中獎號碼-101年11、12月 上的統一發票號碼截取出來



觀察網頁的HTML

會發現在每個號碼都有個class t18red標籤


<span class="t18red"> 55138690</font>

搜尋後剛好是7個 (1個特別奬, 1個特獎, 3個頭獎, 2個增開獎), 所以我們就可以針對這個HTML標籤去做解析

程式碼
See Also
財政部稅務入口網 - 統一發票中獎號碼單

2011年1月13日 星期四

[Python] 計算自己已經活了幾天 calculate your age in days

看自己一年半前寫了一篇Java的文章 : 
[Java] 計算自己已經活了幾天 calculate your age in days

最近都在寫Python, 就想說用Python也來寫一個, 還蠻簡單的。

Python版

Result

你已經活了 9479 天

Java版

跟Java版比起來真的是簡潔太多了。

[有感而發] 很多人事物, 失去了, 就無法珍惜了

「失去了才懂得珍惜」

有很多人、事、物,失去了,就無法再珍惜了。

如果你一直很有錢, 哪天你沒錢了, 你才會想到你是如此的揮霍。
如果有個人對你很好, 哪天他對你不好了, 你才會懷念他對你的好
如果你的電腦一直都正常運作, 哪天他出問題了, 你才開始想著要備份充滿回憶的照片跟重要的工作文件

哪天你家人不在世上時, 你想盡孝道也盡不了了。(子欲養而親不待)
(今天不努力工作,明日努力找工作)

人可能很容易見到, 事很容易重新遇到, 物很容易得到。

但是你永遠不知道你什麼時候會失去什麼。

"改天我們去..."
"有機會我一定要..."

每個人一天都只有24小時, 你有多少的改天跟有機會呢?

珍惜當下吧

想吃就去吃、想做就去做

熱愛生命, 忠於自我, 活出自己的精采人生

2011年1月11日 星期二

[iOS Dev] iOS Development and Objective-C 相關資源與書籍

史丹佛大學完整課程


2011 Stanford University - iPad and iPhone Application Development (HD) by Paul Hegarty
(iTunes U - Video和講義免費下載)




iOS App Resource


Apple官方Sample Code
iOS Reference Library - Cocoa Fundamentals Guide
iPhone Tutorials | Ray Wenderlich




Objective-C


【2011天下經濟論壇】陳聖德:商機將在蓬勃發展的中小企業

了解市場
了解中國政策變化
大陸人才難尋難留, 灰的地方過大
小心選擇夥伴品牌,
中國是一個相信品牌的地方
品牌能夠長線經營會被大家接受
invest in r &d  (投資在開發與研究)


[Python] 時間格式轉換(strtime & strftime)

strftime 將 datetime object 轉換成String
strptime 將 datetime string 轉換成object

>>> datetime.now()
datetime.datetime(2011, 1, 11, 16, 19, 5, 211588)

>>> datetime.now().isoformat()
'2011-01-11T16:20:06.161541'

>>> datetime.strftime(datetime.now(), '%Y-%m-%d')
'2011-01-11'

>>> datetime.strptime(datetime.now().isoformat(), '%Y-%m-%dT%H:%M:%S.%f')
datetime.datetime(2011, 1, 11, 16, 24, 18, 411861)


See Also

http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior

2011年1月9日 星期日

[Blogger] 讓非本站的外部連結, 自動開新視窗

Blogger如果要讓外部連結開新視窗, 都要手動自己加上target="_blank", 非常麻煩

所以寫了一個小程式判斷如果連結不是http://whhnote.blogspot.com開頭 就會另開視窗

展開小裝置範本後, 搜尋</body>

在</body>上面加上如下Code:

<script type="text/javascript">
jQuery("a").each(function(index) {
    var r = new RegExp("^http://whhnote");
    if (!r.test(jQuery(this).attr('href'))) {
        jQuery(this).attr('target', '_blank');
    }
});
</script>

Code中間的http://whhnote改成你自己網站的網址


我有用到jQuery, 通常Blogger應該都會讀取, 如果發現沒辦法用, 將以下code加在上面的Code的上面

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

[Blogger] 在文章上方顯示 麵包削 Breadcrumb

效果如圖所示


到後台-> Design(設計) -> (Edit) 編輯HTML


打勾 Expand Widget Templates (展開小裝置面版)


按Ctrl + F 搜尋 ]]></b:skin>

在該code正上方貼上CSS:

.breadcrumbs{ 
  padding:5px 5px 5px 0; 
  margin:0;font-size:95%; 
  line-height:1.4em; 
  border-bottom:4px double #cadaef; 
}

接著搜尋 <div class='post hentry

在code正下方貼上:

<!-- breadcrumb -->
<b:if cond='data:blog.homepageUrl == data:blog.url'> 
<b:else/> 
<b:if cond='data:blog.pageType == "item"'> 
<div class='breadcrumbs'> 
Browse » <a expr:href='data:blog.homepageUrl'>Home</a> » 
<b:if cond='data:post.labels'><b:loop values='data:post.labels' var='label'> 
<a expr:href='data:label.url' rel='tag'><data:label.name/></a> 
<b:if cond='data:label.isLast != "true"'> , </b:if> 
</b:loop> 
</b:if> » <data:post.title/>
</div> 
</b:if> 
</b:if>
<!-- breadcrumb -->

2011年1月6日 星期四

[Python] convert Unicode to Big5

有時候抓出來的中文unicode字串像這樣 \u55ae\u8eca

結果找一堆資料, 試了unicode, encode, decode都試不出來

結果昨晚就到Stack Overflow去問問看, 果然有一堆好心人幫忙回答

沒想到只要unicode-escape就解決了

str = '\u55ae\u8eca' # It mean '單車'
print str.decode('unicode-escape')

See Also

How to convert utf-8 string to big5 with python? - Stack Overflow

2011年1月5日 星期三

[Python] 安裝Pyflakes Python語法檢查工具及設定Komodo Toolbox

pyflakes 是用來檢查Python程式語法用的, 可以提示未命名的變數或是沒用到(unused)的變數


passive checker of Python programs


Pyflakes is program to analyze Python programs and detect various errors. It works by parsing the source file, not importing it, so it is safe to use on modules with side effects. It's also much faster.


檢查結果如圖所示





[Cherokee] 解決 favicon.icon 500 Error

到Admin介面的vServers

到Rule Management新增一個Rule

Regular Expression: ^/favicon.ico$
Handler: Static Content

然後Save即可


2011年1月4日 星期二

[Python] Convert dateime string by Twitter 轉換從 Twitter API 抓出來的時間

轉換從 Twitter API 抓出來的時間

Twitter API抓出來的時間 Created_at 會像這樣

Tue Jan 04 05:27:30 +0000 2011

所以要轉換成自己要的格式才能存進資料庫

from datetime import datetime, timedelta

created_at = 'Tue Jan 04 05:27:30 +0000 2011'
utc_offset = '28800' # +0800   60 * 60 * 8

created_at = datetime.strptime(created_at, '%a %b %d %H:%M:%S +0000 %Y')
local_time = created_at + timedelta(seconds = int(utc_offset))

print created_at
print local_time

Result
2011-01-04 05:27:30
2011-01-04 13:27:30

抓出來的時區是+0000, 所以要再加上UTC_Offset, 才會是本地時間


See Also

Python Documentation - 8.1. datetime — Basic date and time types
在 app engine 使用 pytz
Twitter API Documentation

2011年1月3日 星期一

[Django] Deploy Django on Cherokee Web Server by uWSGI

Cherokee Web Server

The Fastest free Web Server out there!
Cherokee is a very fast, flexible and easy to configure Web Server. It supports the widespread technologies nowadays: FastCGI, SCGI, PHP, CGI, uWSGI, SSI, TLS and SSL encrypted connections, Virtual hosts, Authentication, on the fly encoding, Load Balancing, Apache compatible log files, Data Base Balancing, Reverse HTTP Proxy, Traffic Shaper, Video Streaming and much more.

Cherokee-Admin, a user friendly interface, provides a no-hassle configuration of the server. Check out the benchmarks and documentation to learn more, join our active Community and give it a try to squeeze your hardware to the fullest!

Related Posts Plugin for WordPress, Blogger...