星期二, 8月 17, 2010

慢跑路線

話說最近常在台大校園慢跑, 我討厭跑操場, 所以都繞校園~
走校內空氣較好的路線.

今天達成小目標:2圈, 特此記念一下 哈哈
保持在心率150左右,2圈總計2.72 * 2 km.
大約是40分鐘跑完5.4k

跑完後神清氣爽才是有氧運動阿~
藍粗線是路線圖. 也許改天試試大安森林公園 ?


View 台北 in a larger map

星期二, 5月 18, 2010

Linux中的Type with Constant Length

許久以來,programming時常看到一堆類似的type define.

今天剛好用到,就整理一下嘍













---------------------





Linux中用户态和内核态定义了若干定长类型, 以32位无符号整数为例:





u_int32_t (BSD类型,目前netfilter中就使用这种类型)





用户态定义位于sys/types.h





在内核态见头文件include/linux/types.h





typedef __u32 u_int32_t;





uint32_t (C99类型, 内核态和用户态都能使用的类型,可移植性更好)





在用户态中见头文件/usr/include/stdint.h





在内核态见头文件include/linux/types.h





typedef __u32 uint32_t;











u32





typedef unsigned int u32;





include/asm-i386/types.h





只能在内核态使用











__u32 (Linux严格类型,内核中应该使用这种类型)





typedef unsigned int __u32;





include/asm-i386/types.h





也可以在用户态使用











unsigned long





unsigned int





标准C语言整数类型, 架构相关













----轉自周知远的博客













總結來說,推薦使用 uintxx_t 系列的C99 type.





只要include 即可。




















星期四, 4月 22, 2010

XiphQT + Fluke = Flac in iTunes

Well, since Flac is more and more popular in world of music sharing, it's time to let iTunes support Flac !

There're some trick about flac in iTunes:

First, you need to install XiphQT to play flac with Quicktime core.

Then you still need a plugin named Fluke. Since iTunes won't accept flac ether in dragging files into iTunes database or double clicking flac files, with Fluke, you could cheat iTunes to add flac when double click on flac files.



http://www.xiph.org/quicktime/download.html

http://blowintopieces.com/fluke/



星期三, 2月 24, 2010

Network Setting problem in Ubuntu 9.04

I believe many people have seen "wired device not managed" in Ubuntu network-manager in gnome.
And even if you know how to set a /etc/network/interface config file to manually start networking, you get no nothing after reboot system.
A simple way to solve this problem is set
[ifupdown] managed=true
in /etc/NetworkManager/nm-system-settings.conf to resolved the issue.

Keyboard & Mouse settings in OS X Terminal

Are you bothering with no PageUp/Down & Home/End key to use in Terminal ?
Well, just set the following keyboard mappings in OS X Terminal preferences.
And you'll get all keys work !
Key       Escape Sequence
Home      \033[1~
End       \033[4~
Page Up   \033[5~
Page Down \033[6~

Besides, if you would like to scroll terminal by mouse,  MouseTerm will be helpful.

星期一, 12月 07, 2009

work around with vimdiff + cvs diff

We'd like to make cvs's diff output colorful.

If you're vim people, you could do it in 2 ways.



  • Redirect cvs diff to vim by "| vim -".

    Then change highlight settings in .vimrc as follows:




    • hi diffAdded ctermfg=Yellow ctermbg=DarkGray guifg=Yellow


    • hi diffRemoved ctermfg=Red ctermbg=DarkGray guifg=Red




  • Or, you could use vimdiff by running the script(cvsvimdiff.sh) in the end.

    This script let you enjoy vimdiff's block diff with cvs.

    Usage: "cvsvimdiff -r version1 -r version2 filename"

    Besides, you should change color scheme to make a comfortable displays of vimdiff.




    • hi DiffAdd term=reverse cterm=bold ctermbg=green ctermfg=white


    • hi DiffChange term=reverse cterm=bold ctermbg=cyan ctermfg=black


    • hi DiffText term=reverse cterm=bold ctermbg=gray ctermfg=black


    • hi DiffDelete term=reverse cterm=bold ctermbg=red ctermfg=black





The following is cvsvimdiff.sh. You can create it and put it in your PATH.



#!/bin/bash

#

# Copyright (C) 2005-2006,

# Stefano Zacchiroli

# Enrico Tassi

#

# This is free software, you can redistribute it and/or modify it under the

# terms of the GNU General Public License version 2 as published by the Free

# Software Foundation.

#



vimdiff="vimdiff"

suffix="vimcvsdiff"

rev1="HEAD"



if [ "$1" == "-g" ] ; then

vimdiff="gvimdiff -f"

shift 1

fi

if [ "$1" == "-r" ]; then

rev1="$2"

shift 2

fi

if [ "$1" == "-r" ]; then

rev2="$2"

shift 2

fi



files="$1"

if [ -z "$files" ]; then

files=$(cvs -n update -r HEAD 2> /dev/null | grep -e "^[MU]" | cut -c 3-)

fi

for f in $files; do

if ! [ -f $f ]; then break; fi

patch=`mktemp $prefix.XXXXXX`

orig=`mktemp $prefix.XXXXXX`

trap "rm -f $patch $orig" EXIT



if ! [ -z "$rev2" ]; then

tmp1=$f.$rev1

tmp2=$f.$rev2

cvs up -p -r $rev1 $f > $tmp1

cvs up -p -r $rev2 $f > $tmp2

$vimdiff $tmp1 $tmp2

rm -f $tmp1 $tmp2

else

cp "$f" $orig

cut -d '/' -f 2 < CVS/Entries | grep "^$f\$" > /dev/null || break

cvs diff -r $rev1 -u "$f" > $patch

if ! [ $? -eq 1 ]; then break; fi

cp "$f" $orig

patch -R -p0 $orig $patch

$vimdiff $orig $f

fi

done


星期日, 11月 22, 2009

iphone addressbook 排序方式


iphone的contacts有很多種排序方式。比如筆劃、拼音、英文字母排序等。以OS 3.1.2而言,排序方式是照系統語系設定;繁中=筆劃,簡中=拼音,英語=字母。然而,筆劃排序不受大眾所喜愛。(除了很熟字典的人,誰會用筆劃排序阿Orz) 所以就出現了許多workaround;像是在last name寫" C.陳"。如此的確可以讓contact照拼音排序,不過又醜又麻煩。



後來,我查到了contact中有隱藏欄位「Phonetic Last/First Name」。如果在OS X中的AddressBook加入此欄位,並且在Phonetic Last Name中打上羅馬/漢語拼音。那麼就會照拼音排序嘍~!

這似乎是個perfect solution ?



不。當以上的方式,碰上了iphone voice control,一切就變了樣。以3.1.2而言,Voice control已經可以獨立設定語系。可是當你用中文發音之後,voice control的reply竟然是讀phonetic name..... 以小弟的聽力,實在是很難確認是哪個人名,還得看iphone螢幕確認一次。這麼一來,voice control的實用性大幅下降。



所以,要兼顧2者的實用性,最好的方式就是將contact排序與系統語系分開設定。

以下就教你,如何自訂contact的排序方式~



原來contact中的排序方式,是寫在以下的plist中。



/System/Library/Frameworks/AddressBook.framework/xxx.lproj/ABContactSections.plist


所以只要把想要的排序方式從A語系copy到目前的系統語系,就能轉換成所要的排序方式!



比如我想要讓英語界面下的addressbook以簡中的拼音方式排序,那麼就進入ssh



iphone#cd /System/Library/Frameworks/AddressBook.framework/Englist.lproj/

iphone#mv ABContactSections.plist ABContactSections.plist.origin

iphone#ln -s ../zh_CN.lproj/ABContactSections.plist ABContactSections.plist


然後重開機,或是把系統語系換成別的再換回來。即可生效!

星期六, 11月 21, 2009

Iphoto 09 face recognition - rescanning faces

Since my iphoto is a mass, I dont want to recognize faces before finishing photo organization.
After the work done, I just cant find the option of "rescanning faces" !

How thankful as I saw the tips of enable rescanning in apple-support-discussions by BobbrkerMyHero.

Here comes the solution of rescanning faces.
**Before we start I recommend you BACKUP your iphoto with time machine or manually, or whatever you want to do. If you don't back it up and for some reason it doesn't work, don't blame me**

If you want to rescan the faces in your library this is all you need to do:

***CLOSE IPHOTO BEFORE YOU START THIS***
Open finder, go to your pictures folder.

-Find the "iPhoto Library"
-Right click (control click) on it
-Click "Show Package Contents"
-Find the files that hold the face detection information
Should be something like:
"face_blob.db"
"face.db"

-You need to move these files out of the folder, you can either delete them, or just move them to the desktop just in case something goes wrong.
-Open iPhoto back up, and it should rescan for faces!
-If everything goes correctly, you can delete the old files you moved to your desktop if you didn't delete them before.

星期二, 11月 10, 2009

[WTF]iphone contact + google contact + facebook photo

目前還沒有看到傻瓜化的app能做到iphone + google + facebook sync
原因不外乎是google本身提供的name只有一個欄位, 且sync時只會把"完全"一樣的contact合併。
除非平常就把google contact整理的很好,不然.... sync下去只會讓iphone內更亂而已

另外, 以中文語系的使用者而言,按姓氏拼音/筆劃排序,是比較實用的方式。
不過目前iphone採用中文界面=筆劃,英文=phonetic(預設未開啟此欄) last name sorting

更有趣的是,如果你喜歡用聲控撥號,那麼phonetic last/first name會影響到iphone 3gs內部的發音。如果單純使用last/first name,那3gs的聲控還算完美。

以聲控+contact排序而言,看來是需要一套app能不依賴phonetic欄位,將contact以喜愛的方式排序,如此就能兼顧兩種功能。

星期日, 9月 06, 2009

Windows Media Player 12 with srt

I'm using win7 x64, coreavc 1.9.5, wmp 12.

when I install the k-codec pack x32, the wmp12 will only detect the embedded subtitles (through direct vobsub x32). no matter what file name of srt in the same folder, the wmp12 just cant detect it!

Now I found a solution. It perfectly solves the subtitle problem for a few srt files with a mkv (embedded subtitles).
Just download

K-Lite Codec Pack 64-bit

And you'll find out the wmp12 works fine with a direct vobsub x64 version.

btw..
I think it's time to switch from wmp classic to wmp12.
In my expierence, when playing large video files, the performance of wmp12 is better than classic player.
1. wmp12 is faster than classic player as program start to play.
2. wmp12 is faster than classic plaer as we seek to any point.

the simple classic player has poor I/O efficiency as loading hd rip files( 4G+ ).

========== 9.11 newly added=======
Solution for Windows media player 12 + coreavc + directvobsub(k-lite pack x32)

It's strange that wmp12 can't detect .srt files when loading coreavc.
there's a solution in coreavc's forum:
unselect the "preferred decoder" in coreavc's configuration.
then, directvobsub is loaded !

Windows Media Player 12 with CoreAVC filter

久違的技術文章!!
自從升級到了win7之後,還未試過看h.264...
結果今天才剛碰 就遇到問題。

雖安裝了coreavc 但是內建的wmp12不賞臉。
播放後,就是只用windows寫的video filter解碼
google了網路的解法,沒有total solution. 有些人是改registry,不過此法對我無效...
然而劇情極轉直下,在更新k-codec pack時,看到了下面一行...

Tools: Preferred Filter Tweaker for Windows 7

咦
這可是9/1之後才有的好東西阿~XD
執行後直接改filter,馬上跟win7的機車filter說bye bye



星期日, 11月 02, 2008

成功嶺的3個哨站位置

轉自http://www.wretch.cc/blog/milkmilk777/17280418

1.成功嶺大門--如由烏日鄉的中山路三段進入(和進入成功嶺大門這條路是丁字路,路口有紅綠燈,在中山路上有萊爾富便利商店),還要經過鐵路平交道和中山高速公路的高架橋,而此時亦可看到成功嶺走向成功之路的圓拱門,再進入就是右手邊的成功東路,而在左手邊是往旭光國小的招牌(就立在路邊),前方即是成功嶺的大門了。


2.而成功嶺二號門所在的地點,您從這裡(大門前)要右轉走成功東路,沿成功東路往成功社區方向走,路途中左邊有小公園,往這條路走約400公尺左右,您就會到達成功東路和便行巷的丁字路口,右手邊是排水溝(此路約是一部中型貨車可通行的道路),左手邊即是商家,(皆是以阿兵為消費對象),您沿此路走(沿途爬坡道路),約是500公尺左右就到達成功嶺的2號門,亦是此路的盡頭,左手邊有一嶺中軍用品店和附設停放機車,招牌很大很好認的。


3.又成功嶺三號門,就是剛才經過的便行巷丁字路口處,要從2號門往3號門就得從這便行巷前往,由此巷走首先會遇到成功社區中的建興宮(在左邊),此巷更小了但是也有小發財車再行駛,沿此巷一直走,就會和學田路相交會(丁字路口),然後左轉學田路,再遇到右手邊有一間好朋友軍用品店時左轉就是成功嶺三號門,從路口到大門約不到100公尺,而軍用品店正好在大門路口的對面,而且在軍用品的斜面面是台糖加油站,目標是很顯目的。

另外的方式還有..
(1)--從環中路一直往南屯方向走(您是開車或是騎車呢,開車的話就走高架橋中彰,騎車的話那就走高架橋下的平面道路),一直到台中市魚市場(經過五權西路和環中路二段的十字路口後,在右手邊),再經賽鴿協會(右邊)、變電所,右轉永春路,沿永春路往嶺東方向走,經過筏子溪橋,走左邊的永春東路,然後會遇到三叉路口,左正前方是要往嶺東科大和台中監獄,您要左轉走忠勇路,沿忠勇路一直走會看到右邊有高爾夫練習場(就在路旁),經過練習場後,前方右邊即是台糖加油站,而其旁邊就是成功嶺3號門。

(2)--而您如要前往2號門,您就再直走,經過3號門之後忠勇路就變成學田路了(因這裡是烏日鄉的行政區域了),沿學田路一直走,會先遇到右邊的山頂巷,經過後約是600公尺就再遇到學田路便行巷,而您要在此右轉進入,沿此巷(順巷道彎路前進)一直走,經過建興宮後,再直走就會遇到成功東路旁的大水溝,然後右轉走到盡頭就是2號門了,如要前往大門,您就左轉一直走就會直接到達大門(右邊)。

星期日, 5月 18, 2008

四川災區 急需 260 万顶帐篷!!!

今天早些时候,谷歌接到来自四川震区政府和摄制组的求助信息,由于一直下雨,绵阳北川地区的大量灾民情况非常堪忧,现在急需可以让灾民避雨的60万顶帐篷!根据下午四川政府最新发布的信息,全省急需帐篷总共260万顶!

借助网络的力量,让更多的人了解灾区的求助信息,协助灾区的同胞最大限度地得到帮助,是我们AdSense小组每一位成员最大的心愿和义不容辞的责任。为此,我们恳请广大发布商在看到这一消息时,请立即在您的网站上帮助发布这一信息,使得我们灾区同胞能够少度过一个冰冷潮湿的夜晚,多一份温暖。

一个网站的力量有限,联合起来力量无穷。您的帮助和努力对灾区人民是莫大的希望。在此,我们衷心希望所有的发布商和我们联合起来,充分发挥我们手中互联网的力量,为抗震救灾出一份力!

我们今后还会不断发布来自灾区的求助信息,如果您愿意和我们携手帮助灾区同胞抗震救灾,重建家园,请您注册 Google AdSense 抗震爱心联盟 https://spreadsheets.google.com/a/google.com/viewform?key=psN9iO-vpoNkmBZ20KeBkEQ ,我们会在需要的时候第一时间与您联络。另外,也请您放心,您所提供的联系方式将仅作为抗震救灾联系所有,我们将严格保护您的信息隐私。

最后,我们对您的帮助表示由衷的敬佩和感谢!

Google AdSense 小组敬上

星期三, 3月 05, 2008

台灣兵營的趣味描述....

話說今年的預官說明會,教官說了句很貼切的話...
軍中生態一言以蔽之,就是狗官、爛兵與刁民啦

入營當狗官
帶了一堆爛兵
住在旁邊都是刁民的營區

雖說有些誇飾,但也是其中的某些人的經驗吧

另外語重心長的提醒語是「學習軍中的另一種文化」
「不妨嘗試與長官妥協,當任務無法如期完成,或超出自己的能力,坦言且虛心求教」

星期六, 11月 03, 2007

Hibernate on OSX

As on Tiger, we have already had the hibernate functionality. Apple call it "Safe Sleep". Some people might use "Deep Sleep" for it.

Safe Sleep is to use /var/vm/sleepimage for saving data in the RAM to disk (by default). And once you lost your power of Mac, Tiger will read the sleepimage and restore your working stage. But in Energy Saver, there's no option about this Safe Sleep functionality. Many people said that you can input root#pmset hibernatemode 3/0  to switch safe sleep on/off. What if I want to safe sleep then power off ( just like Linux and MS' system doing ) ? The answer is unclear. Until....

I saw the article about new options of Leopard's Hibernate and a "Hibernate Bear".
Now I understand, the Evil Apple just hide the power manager's functions again.
So, if you aren't interested in HOW TO CUSTOMIZE YOUR SLEEP MODE. Just try the Bear above first. The bear support 3 sleep modes. That may satisfy your need.
##CONTINUE##
For further tuning about energy saving, I tried to man pmset. 
It said that 
  • hibernate mode=0: This mode is to perform normal sleep. NOT safe sleep.
  • hibernate mode=1: This mode is to save data to sleepimage then shutdown.
  • hibernate mode=2: This mode is a SMART one. It will perform normal sleep when the battery is full. And when battery level is under "Hibernate Free Ratio"( Integer percentage ),  it will change to perform safe sleep. 
  • hibernate mode=3: This mode is to save data to sleepimage then sleep. If you lost power supply, OS X will use sleepimage to recover working state.
Because I use Macbook pro, and the energy saving is important for a notebook. So, I tuned as follows.pmset -b hibernatemode 2 hibernatefreeratio 5 
pmset -c hibernatemode 0

星期五, 11月 02, 2007

Parallels on OS X

最近試了將Parallels裝在Leopard上。有些心得與設定事項要注意。
  1. 因為Parallels有自動的post install,所以最好是用正版的Winxp安裝。
  2. 即使是用繁中的原版光碟安裝系統,在控制台/語言的設定中,卻是英文。這會造成一些亂碼與錯誤。比如 當你想要安裝程式時,卻出現了 NSIS Error 的錯誤。那麼請先去改成中文語系設定。
  3. Virtual Machine的設定從「Shared networking」改成「Bridged Ethernet」。速度會比較快一些。
  4. 聽說 usb的外接device會使得parallels不穩,但firewire就無此問題。
其它的小問題,等遇到了再來記錄~

星期四, 11月 01, 2007

TCP connections in OSX

隨著P2P分享軟體的增加,愈來愈多人使用這類軟體,使得本來的TCP連線數不夠用。
雖然調過Winxp上的TCP連線數,但是OS X上的要怎調整呢?

其實很簡單。因為OS X底層是採用FreeBSD的改良,所以調整系統參數的方法與FreeBSD相同。
使用sysctl這指令即可。
相關的文件可參考
Mobile01 【分享教學】使用sysctl 調校你的OSX (之一) 之二

星期四, 10月 25, 2007

Gmail in email clients

Today, I saw the news of Gmail's IMAP support.
IMAP( Internet Message Access Protocol ) can let you communicate with gmail's server and you can make changes with your mails as mails on gmail's server are applied changes immediately.

I've given up mail clients( outlook, thunderbird ... etc. ) many years, since their inconvenient occurs as I switch among 2 or more computers. Such as downloading your email with POP3, unsynchronized email as you downloaded them.

Hence, webmail service seems the only way to solve this problem. And gmail is indeed an outstanding mail service today. Now, may IMAP combine mail client application with webmail service perfectly ?

In my experience, IMAP with lots of mails will lower its performance and users have to wait "few seconds".

星期六, 10月 13, 2007

Textmate的543

Well, seems textmate is the best code editor about keyword/code completion.
Although there are so many hotkey you need to remember before you can perform a MAGIC completion of all kinds of programming language, it still is worth a try.
##CONTINUE##
IF you are a vim user or your mother-tone is a CJK-language, you MIGHT need the following plugins of textmate.
There are so many "programmers" using VIM or something else. And some key bindings are very important, especially vim's hjkl moving mode. But native textmate doesn't support this.

Hence, the "vimate" was born and it is still under developing. The most recent update is on Sep. 07'.

Another important thing is the width of the CJK words are 2-byte and obviously textmate treat them as 1-byte font. 
A good news is textmate 2.0 will support utf8. But just like the slogan of apple's new OS - ONLY IN LEOPARD ! Yes, textmate 2.0 is only in leopard. Damn...

Before apple ships leopard, we have another solution: make a new font with 1-byte-width CJK word. Thanks to Japanese-hetima to provide this idea and shinbang to provide his own new font.

星期日, 10月 07, 2007

itunes的istore帳號

因為萬惡的itunes增加了album photo的功能,itunes 7更是以3D的方式展現類似點唱機的感覺。所以大家就開始補完專輯的封面嘍~
而想用itunes自動抓取istore的專輯封面,就得要先有istore的帳號。雖然有高手寫了plugin抓網頁的圖片,不過最近又被擋了。看來,還是要有個正統的帳號才是王道。( 當然,也可以用google picture找圖,省了一堆麻煩 )
拿到帳號的方法,就我所知有下列方式
  1. 有美國的帳戶:正式的傳統方法,當然可開通istore帳號
  2. 有台灣的visa卡:先用visa開通paypal的帳號,然後利用paypal去申請istore
  3. 利用apple gift card的redeem code:這是apple行銷的手法–推出gift card,上面印有可儲值的密碼,所以可以用這串東東申請帳號。
  4. 利用....apple 網頁錯亂法 冏... 這是有緣人才能用的方法.
先說明(2),聽說用「中國信託」的visa卡,在paypal上註明是US,填上US地址;如此一來,在istore認證paypal帳號時,就能過關。
再來是前陣子很流行的(3),對岸的同胞也有滿多人用這類方法。(果然中國人都愛貪小便宜...) 簡言之,就是在網上的某些網站提供一批redeem code,而如何申請...可以google或參考下列討論。
http://blog.pixnet.net/ayhaadam/post/2629899
http://forums.macrumors.com/showthread.php?p=2022710
http://www.elesson.com.cn/modules/ipboard/index.php?s=&showtopic=38602&st=0
http://www.mobile01.com/topicdetail.php?f=177&t=228626&last=1907422
http://www.wretch.cc/blog/singho&article_id=12808440

最後,是神祕的(4)。因為在找(3)的時候,發現有人說「其實apple改了機制,能在網頁選取none的付費方式」(樣本數1),所以也許點個10、20次申請帳號就能通過?? 不不,我的經驗是,在redeem code填寫了過期的code,然後在失望的心情下,到處找能用的redeem code;最後要死心用paypal註冊之時,熊熊發現付費那格多了none ! 就降子,申請到了帳號。這帳號沒有credit card、沒有redeem code送的點數,算是個空帳號。這樣子的流程,讓我覺得應該是在之前填入redeem code時,apple雖然告知了過期,但是回去首頁申請帳號時,卻把它當做是使用redeem code型態的申請帳號。因此,雖然沒有能使用的redeem code,但是還是把帳號搞到手了。