標籤

C++ (12) Linux (6) MacOSX (4) Makefile (3) Matlab (3) Ubuntu (3) Android (2) C (1) Refactoring (1)

2011年12月28日 星期三

[Android] Intent, result, callback

廢話就不多說了
直接提供網址:
http://www.kfsoft.info/article-43-11--%E8%99%95%E7%90%86Activity-Result.html

寫得滿好的
希望因為我多加了一個inlink
可以讓他的blog被更多人看到XDD

[Android] thread, join

join的解釋如下:

final voidjoin()
Blocks the current Thread (Thread.currentThread()) until the receiver finishes
its execution and dies.
final voidjoin(long millis, int nanos)
Blocks the current Thread (Thread.currentThread()) until the receiver finishes
its execution and dies or the specified timeout expires, whatever happens first.
final voidjoin(long millis)
Blocks the current Thread (Thread.currentThread()) until the receiver finishes
its execution and dies or the specified timeout expires, whatever happens first.
來源資料:http://developer.android.com/reference/java/lang/Thread.html

2011年12月22日 星期四

[C++] header, static and compilation

自己做研究寫c++時
如果檔案一多起來
Makefile就變得很重要
通常程式還算小的話
只要搭配#include guards用#ifndef, #define, #endif
並把每個class的宣告(Prototypes, Definition)寫在.h檔
把實作的部分寫在.cpp檔裡
用makefile把所以class都分別compile在用link起來就沒啥問題了

但class小的時候
把宣告跟實作分別寫在.h和.cpp檔真的頗為麻煩
尤其當class只是簡單container沒啥功能時
撰寫cpp檔更是顯得很冗又很繁瑣

用#include其實就是把檔案先直接嵌入
再行編譯
所以如果有任何的初始化(initialization)出現在.h檔裡
那該.h檔就只能被一個.cpp程式引用
因為當有同時有兩個.cpp引用的該header
則兩個cpp檔都會做相同的初始化動作
這會導致最後一步link所有cpp檔編譯完的.o檔時
產生變數名稱衝突的問題

簡單來說就是相當於一樣的變數名被宣告兩次

避免發生這問題有幾個方法:
1) 不要在.h檔裡初始化,這樣就不會在多個檔案被allocated
2) 如果一定要在.h檔裡初始化,那就確保該.h檔只被一個.cpp檔引用

參考來源:
http://stackoverflow.com/questions/2470737/why-cant-initialize-the-static-member-in-a-class-in-the-body-or-in-the-header-f

2011年11月13日 星期日

[c++] 資料結構ADT之容易Crash的點

每次建新的class時
都很開心地寫了一堆member function
結果function明明就沒有問題
可是一用就segmentation fault (囧)
而且通常也cout不出個所以然...
(當然也是可以用gdb啦...)

下面列了幾個很容易crash的點:

<狀況一> 忘了寫copy constructor 和 operator =

2011年11月12日 星期六

[MacOSX] vim裡的Home和End

一直無法在vim裡用Home和End
快被搞死了

最後查到把下面8加到~/.vimrc裡就ok了
map <Esc>[H <Home>
imap <Esc>[H <Home>
map <Esc>[F <End>
imap <Esc>[F <End>
map <Esc>[5~ <PageUp>
imap <Esc>[5~ <PageUp>
map <Esc>[6~ <PageDown>
imap <Esc>[6~ <PageDown>
資料來源:http://serverfault.com/questions/73013/vim-keyboard-remap-on-snow-leopard-macos-10-6

2011年11月10日 星期四

[ctags] 在Mac OS X下配合Vim

直接去抓ctags-5.7.tar.gz

下載完後用tar zxvf解壓縮

接著./configure && make all && sudo make install

最後最後
也是最重要的一步
因Mac OS X下本來就有安裝另一種ctags
所以記得在開啟Terminal時要更改$PATH

export PATH="/usr/local/bin:$PATH"

這樣使用時才會真正執行我們想要安裝的ctags喔

2011年11月9日 星期三

[Matlab] Property Editor 圖片編輯

如果你是第一次使用simulink的話
應該會發現在simulink裡所有的scope
不論是一般的(time-domain) scope、spectrum scope或是PSD scope
開啟的圖片不但不能編輯
連存檔都有點困難(還要用printscreen = =)

要解決這個問題其實很簡單

2011年10月30日 星期日

[Ubuntu] Terminal裡長長的路徑

修改 ~/.bashrc
找到裡面的這行:PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
把最後面的小寫w改成大寫的W

小寫w是 絕對路徑
大寫W是 當前目錄

更改後重開Terminal就OK了

2011年10月29日 星期六

[HTK] Compile & Build

環境:Ubuntu 11.04 (64 bits)

下載HTK解壓縮後

一定會遇到一堆error
因為缺了一堆lib沒安裝

64 bits下


sudo apt-get install build-essential libc6-i386 libc6-dev-i386 xorg-dev libx11-xcb-dev ia32-libs



2011年10月27日 星期四

[C++] Forward Declaration and Definition

如果要給函式default argument或是在class 的 constructor 進入函式前就先初始化data member
都只要加在Definition的地方就好(Implementation)
不需要在forward declaration補上
如下:

class A {
public:
    A(int a = 10): _a(a) {}
private:
    int _a;
};

可以拆開成

// File: *.h

class A {
public:
    A(int a);
private:
    int _a;
};

// File: *.cpp
A::A(int a = 10): _a(a) {
    // TODO
}

2011年10月20日 星期四

[Signal Processing] Spectral Density Estimation

開wiki看到的

估計的方法有兩種
1) Parametric Approach
2) Non-Parametric Approach

其中parametric 比較有趣
"assume that the underlying stationary stochastic process has a certain structure which can be described using a small number of parameters"
就是假設random process背後其實有一些結構與機制
想辦法去找出那些parameter來理解random process的產生方式與原因
進一步估計Spectral Density Estimation

不知道這樣理解對不對??

2011年10月14日 星期五


cd r8168-8.025.00/
sudo rmmod r8169
sudo mv /lib/modules/`uname -r`/kernel/drivers/net/r8169.ko ~/r8169.ko.backup
make clean modules
sudo make install
sudo depmod -a
sudo insmod ./src/r8168.ko
sudo mv /initrd.img ~/initrd.img.backup
sudo mkinitramfs -o /boot/initrd.img-`uname -r` `uname -r`
sudo echo "r8168" >> sudo /etc/modules
lspci -v
sudo reboot

2011年10月13日 星期四

[C++] 用fstream , string , substr, find來讀檔

每次遇到要用fstream讀檔案時
都覺得很麻煩
尤其是string的find和substr
每次Google每次忘記
所以這次要把它記下來!!

fstream query_file;
query_file.open("OOVquery.syl.txt", fstream::in);

while(!query_file.eof()) {

    char buffer[256];
    query_file.getline(buffer, 256);
    string eachLine = string(buffer);
    text.append(" ");

    int pos = 0;
    int pos2 = 0;

    while((pos2 = text.find(" ", pos)) != string::npos) {
        string subsyl = text.substr(pos, pos2 - pos);

        //這裡記得要+1,不然會一直找到第一個" "
        pos = pos2+1;         
    }
}

2011年10月12日 星期三

[Linux] Asrock Z68 Pro3 主機板網路卡很慢的問題

如果你是用華擎Z68系列的主機板
而且有灌完Ubuntu 11.04之後
網路慢到爆炸的問題
(連檢查更新套件只有1Byte都要好多秒...)

可以用以下的方法修復網路問題
(筆者試過已成功解決)

『轉載自Ubuntu 11.04 Network speed fix for Z68 boards
(把r8169換成新版的r8168)

1. 先按下Ctrl + Alt + t 進入Terminal(終端機)
2. 輸入ifconfig指令,檢查網路是否有大量dropped package的問題(如下所示)

RX packets:98254 errors:0 dropped:98254 overruns:0 frame:98254
TX packets:72648 errors:0 dropped:113 overruns:0 carrier:0



3. 如果有,請打 wget http://www.foxhop.net/attachment/r8168-8.023.00.tar.bz2 來下載新的驅動程式。

4. 一樣繼續在Terminal輸入 tar jxvf r8168-8.023.00.tar.bz2

5. 安裝前,先檢查是不是有個內建的驅動程式已經在執行(有問題的那個)

    lsmod | grep r8169

6. 如果打完上述指令後,有任何output跳出,代表有在執行(所以要先關掉)。這會暫時關閉網卡。

    sudo rmmod r8169
    (如果有詢問密碼,那就打入自己的使用者密碼吧! )

7. cd r8168-8.023.00

8. sudo ./autorun.sh

9. echo "blacklist r8169" >> /etc/modprobe.d/blacklist.conf

10. 確定新的驅動程式r8168有成功安裝並執行

    lsmod | grep r8168

這樣就大功告成囉!!

[Linux] SSH , SSHD & SSH Tunnel

前幾天剛入手一台i7-2600
想說灌個ubuntu linux server 版
這樣就可以用MBA遠端回linux
出門在外都不用擔心效能不足的問題

所以看了一下ssh、sshd、ssh tunnel等等文章

2011年10月11日 星期二

[Makefile] Implicit Rules

寫Makefile時最容易忘記的就是以下這些自動變數:

$@   代表Target
$?    代表該規則的所有dependencies
$<   代表該規則的第1個dependency
$^    代表整個Makefile中的所有dependencies(感覺不常用)

還有pattern variable,例如:
%.o %.c ...

用法大概如下

default: a.o b.o c.o
        g++ -o outputFile $?                # $? 就是 a.o b.o c.o

%.o: %.cpp %.h
        g++ -c $< [-o $@]                    # $< 就是 %.cpp,$@是%.o(可寫可不寫,因為default 生成的檔案就會根據%.cpp來命名)

意思就是說
當用g++編譯產生outputFile時
會先去檢查a.o b.o和c.o存不存在或是有沒有被動過
對於每個.o檔
makefile會自動去找到%.o: %.cpp %.h這條rule
所以剛剛檢查的動作
就會變成分別檢查 a.cpp a.h、b.cpp b.h和c.cpp c.h
如果相對應的檔案有被更動過的話
則.o檔則會被重新編譯
等到a.o b.o c.o都被檢查過(或被重新編譯過後)
就輪到 g++ -o outputFile $? 了

[Linux] Tar

記下來免得每次都要查...

解tar.gz和tar.bz2時

tar zxvf XXX.tar.gz
tar jxvf YYY.tar.bz2

.gz 用z / .bz2 用j
x 是 解壓縮 extract
v 是 文字顯示解壓縮過程(verbal)
f 後面接檔案名稱(file)

2011年10月10日 星期一

[Retrieval] Keywords

把最近survey到的某篇paper中
不懂的關鍵字都記下來...

ASR (Automatic Speech Recognition)
SDR (Spoken Document Retrieval)
Speech Recognition Lattice
OOV (Out-of-vocabulary)
Precision - Recall Rate
F-measure
MAP (Mean Average Precision)
R-precision
precision-at-N
OOV rate
query-OOV rate
WER (Word Error Rate)
lattice-WER
STD (Spoken Term Detection)
ATWV (Actual Term-Weighted Value)
Word-Spotting Measure

[Retrieval] Precision - Recall & F-measure

最近survey到一篇有關document retrieval的文章
講到Precision和Recall

Precision = GoldenFind / AllFind
Recall      = GoldenFind / Target

簡單來說:

2011年10月6日 星期四

[Steve Jobs]


雖然我不是賈迷
但Jobs確實改變了整個世界

會幫他開了一個標題
是希望也冀望所有念電機系的學弟學妹們
或許有那麼一天
你(妳)也能成為一位用智慧改變世界的人
一位能留給這世界什麼的人
謹記

[Linux] 查詢Linux主機的硬體規格(CPU + RAM)

查詢CPU規格
cat /proc/cpuinfo

RAM規格
cat /proc/meminfo

如果還想進一步查CPU夠不夠力

2011年9月30日 星期五

[Matlab] 頻譜分析

懶得多打
直接貼網址了

http://blog.xuite.net/cmi5288/net/321413 (MATLAB中的離散傅立葉轉換)

[C語言] #define

常見的就不多說了
下面列了幾個每次都會忘記的用法...囧


#define CONCAT(x,y) x##y      // concatenate x & y
#define ToChar(x) #@x            // change x into char
#define ToString(x) #x              // change x into string


2011年9月29日 星期四

[C++] passing "const ..." as this argument discards qualifiers

小時候不懂事
每次code改過看到compile error就把code改回去
(因為error都看不懂 @@)
長大後才發現
原來只是我英文太差= =
compiler其實都寫得滿詳細的

為了解決看不懂compile error的問題
我決定把遇到的錯誤都給它記下來
這樣哪天忘了就不用再Google啦!