星期二, 8月 17, 2010
星期二, 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
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=truein /etc/NetworkManager/nm-system-settings.conf to resolved the issue.
Keyboard & Mouse settings in OS X 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
#!/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
**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
星期日, 9月 06, 2009
Windows Media Player 12 with srt
K-Lite Codec Pack 64-bit
And you'll find out the wmp12 works fine with a direct vobsub x64 version.Windows Media Player 12 with CoreAVC filter
自從升級到了win7之後,還未試過看h.264...
結果今天才剛碰 就遇到問題。
雖安裝了coreavc 但是內建的wmp12不賞臉。
播放後,就是只用windows寫的video filter解碼
google了網路的解法,沒有total solution. 有些人是改registry,不過此法對我無效...
然而劇情極轉直下,在更新k-codec pack時,看到了下面一行...
星期日, 11月 02, 2008
成功嶺的3個哨站位置
1.成功嶺大門--如由烏日鄉的中山路三段進入(和進入成功嶺大門這條路是丁字路,路口有紅綠燈,在中山路上有萊爾富便利商店),還要經過鐵路平交道和中山高速公路的高架橋,而此時亦可看到成功嶺走向成功之路的圓拱門,再進入就是右手邊的成功東路,而在左手邊是往旭光國小的招牌(就立在路邊),前方即是成功嶺的大門了。
2.而成功嶺二號門所在的地點,您從這裡(大門前)要右轉走成功東路,沿成功東路往成功社區方向走,路途中左邊有小公園,往這條路走約400公尺左右,您就會到達成功東路和便行巷的丁字路口,右手邊是排水溝(此路約是一部中型貨車可通行的道路),左手邊即是商家,(皆是以阿兵為消費對象),您沿此路走(沿途爬坡道路),約是500公尺左右就到達成功嶺的2號門,亦是此路的盡頭,左手邊有一嶺中軍用品店和附設停放機車,招牌很大很好認的。
3.又成功嶺三號門,就是剛才經過的便行巷丁字路口處,要從2號門往3號門就得從這便行巷前往,由此巷走首先會遇到成功社區中的建興宮(在左邊),此巷更小了但是也有小發財車再行駛,沿此巷一直走,就會和學田路相交會(丁字路口),然後左轉學田路,再遇到右手邊有一間好朋友軍用品店時左轉就是成功嶺三號門,從路口到大門約不到100公尺,而軍用品店正好在大門路口的對面,而且在軍用品的斜面面是台糖加油站,目標是很顯目的。
另外的方式還有..
(1)--從環中路一直往南屯方向走(您是開車或是騎車呢,開車的話就走高架橋中彰,騎車的話那就走高架橋下的平面道路),一直到台中市魚市場(經過五權西路和環中路二段的十字路口後,在右手邊),再經賽鴿協會(右邊)、變電所,右轉永春路,沿永春路往嶺東方向走,經過筏子溪橋,走左邊的永春東路,然後會遇到三叉路口,左正前方是要往嶺東科大和台中監獄,您要左轉走忠勇路,沿忠勇路一直走會看到右邊有高爾夫練習場(就在路旁),經過練習場後,前方右邊即是台糖加油站,而其旁邊就是成功嶺3號門。
(2)--而您如要前往2號門,您就再直走,經過3號門之後忠勇路就變成學田路了(因這裡是烏日鄉的行政區域了),沿學田路一直走,會先遇到右邊的山頂巷,經過後約是600公尺就再遇到學田路便行巷,而您要在此右轉進入,沿此巷(順巷道彎路前進)一直走,經過建興宮後,再直走就會遇到成功東路旁的大水溝,然後右轉走到盡頭就是2號門了,如要前往大門,您就左轉一直走就會直接到達大門(右邊)。
星期日, 5月 18, 2008
四川災區 急需 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
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....- 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.
pmset -b hibernatemode 2 hibernatefreeratio 5 pmset -c hibernatemode 0星期五, 11月 02, 2007
Parallels on OS X
- 因為Parallels有自動的post install,所以最好是用正版的Winxp安裝。
- 即使是用繁中的原版光碟安裝系統,在控制台/語言的設定中,卻是英文。這會造成一些亂碼與錯誤。比如 當你想要安裝程式時,卻出現了 NSIS Error 的錯誤。那麼請先去改成中文語系設定。
- Virtual Machine的設定從「Shared networking」改成「Bridged Ethernet」。速度會比較快一些。
- 聽說 usb的外接device會使得parallels不穩,但firewire就無此問題。
星期四, 11月 01, 2007
TCP connections in OSX
雖然調過Winxp上的TCP連線數,但是OS X上的要怎調整呢?
其實很簡單。因為OS X底層是採用FreeBSD的改良,所以調整系統參數的方法與FreeBSD相同。
使用sysctl這指令即可。
相關的文件可參考
Mobile01 【分享教學】使用sysctl 調校你的OSX (之一) 之二
星期四, 10月 25, 2007
Gmail in email clients
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
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帳號
- 有美國的帳戶:正式的傳統方法,當然可開通istore帳號
- 有台灣的visa卡:先用visa開通paypal的帳號,然後利用paypal去申請istore
- 利用apple gift card的redeem code:這是apple行銷的手法–推出gift card,上面印有可儲值的密碼,所以可以用這串東東申請帳號。
- 利用....apple 網頁錯亂法 冏... 這是有緣人才能用的方法.
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