星期二, 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.