2011年1月9日 星期日

[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...