星期日, 8月 26, 2012

difference between men and women

I am into difficult situation regarding my job, 
there is  a problem that we need to solve as soon as possible, 
but until now, I cannot find the best way to solve it. 
This situation gave me too much anxiety, 
so I asked my boss but he told me that it's alright and that he will try to look for someone to solve it.
Usually men doesn't like to ask for help because that will mean they are weak or useless 
but you can't solve problem by yourself. 
I think this is the biggest difference between men and women. 
I read  a book  informing me about that but I am not sure if that is true, 
but base on my experience it is proven.

coffee

Although I like the taste of coffee, I usually drink coffee at least once a month. 
If I will  drink too much coffee, I usually experience palpitations. 
Often times  after drinking coffee I can't sleep well which makes me feel uncomfortable.
My wife doesn't feel these symptoms and she can even sleep early after drinking coffee.
In spite of she doesn't like to drink too much coffee because we need to control our food expenses.
In fact drinking too much coffee is unhealthy.
In Taiwan some people are thinking that drinking coffee is a fashion trend, 
because whenever they have  a cup of coffee in their hands,it's  a kind of noble moves. 
In my opinion that's not a bad habit, if they will feel happy and will not try to interfere to other people's lives. Why not?

星期一, 9月 12, 2011

Use C language to get Hard Disk Serial Number in Linux





/*
* It gets the hard disk information in this case serial no.
* It uses ioctl() system call
*/
#include <stdio.h>
#include <string.h>
#include <linux/types.h>
#include <linux/hdreg.h>
#include <linux/fcntl.h>

//
int hd_serial(char *searial_no);
void trim(char *s);
//
int main() {
char serial_no[256];

if (hd_serial(serial_no)){
printf("%s",serial_no);
}

return (0);
}
// ----------------------------------
int hd_serial(char *serial_no){
int fd,err,i;

/* structure to get disk information and
* returned by HDIO_GET_IDENTITY, as per ANSI ATA2 rev.2f spec
*/
struct hd_driveid hd;

/* open the device */
if( (fd=open("/dev/sda", O_RDONLY ) ) < 0 ){
//perror("Device Open Error");
return 0;
}

/* get required info */
if( (err = ioctl(fd, HDIO_GET_IDENTITY, &hd) ) < 0){
//perror("IOCTL err");
return 0;
}else{
//printf("Serial No = %s\n",hd.serial_no);
strcpy(serial_no, hd.serial_no);
trim(serial_no);
//printf("%s",serial_no);
}
return 1;
}
// ------------- trim ---------------------------
void trim(char *s){
int i=0, j, k, l=0;

while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
i++;

j = strlen(s)-1;
while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
j--;

if(i==0 && j==strlen(s)-1) { }
else if(i==0) s[j+1] = '\0';
else {
for(k=i; k<=j; k++) s[l++] = s[k];
s[l] = '\0';
}
}
//----------------------------------------------


星期四, 8月 18, 2011

網路看到的笑話幾則

一對夫妻在蜜月旅途中....車突然拋錨~
男下車修理~搞了老半天都弄不好~
女:天色漸晚了耶~前面有家汽車旅館~我們過去那裡休息~說不定跟上次 一樣~睡一覺後車子就會好了~
男:那次是結婚前好不好~這次是真的車子壞了!!!

-----------------------------------------------------------------------------------
一女從計程車下車,司機突然從車里探出頭:小姐,你像雞!
女臉一紅,罵到:你他X的像隻鴨。
司機聽了不爽,然後就快速開走了。








然後女孩突然想起追著車喊:運將,我相機,我相機!
-------------------------------------------------------------------------------------
廣東一夥劫匪在搶劫銀行時說了一句至理名言:“通通不許動,錢是國家的,命是自己的!”
大家一聲不吭躺倒。
劫匪望了一眼躺在桌上四肢朝天的出納小姐,說:“請你躺文明些!這是劫財,又不是劫色!”
劫匪回去後,其中一個新來的碩士劫匪說:“老大,我們趕快數一下搶了多少錢。”
那老劫匪(小學畢業)說:“你傻啊?這麼多,你要數到什麼時候啊?今天晚上看看新聞不就知道了嗎。”

——這就叫工作經驗,這年頭工作經驗比學歷更重要!!!

劫匪走後,行長說,趕緊報案!
主任剛要走,行長急忙說:“等等!把我們上次私自挪用的五千萬也加上去!”
主任會意,陰笑道:“要是劫匪每個月都來搶一回就好了。”
第二天,新聞聯播報導銀行被搶了七千萬。
劫匪數來數去只有兩千萬。
老大罵道:“媽的,老子拼了一條命才搶了兩千萬,銀行行長動動嘴皮就賺了五千萬,看來這年頭還是要讀書啊!

---------------------------------------------------------------------------------------------------
高官兒子愛逃學說謊。為此高官高價買一測謊機器人。

一日兒晚歸。
父:去哪裡了?
兒:圖書館。
機器人一巴掌摑過去。

兒:去同學家看A片了。
父:膽子好大,我長這麼大從未看過。
機器人隨即給其父一巴掌。

母怒斥父說:活該,對兒子這麼苛刻。再怎麼說他都是你親生的呀!

啪!機器人又給其母一個大耳光!
-----------------------------------------------------------------------------------------------------------------



星期四, 5月 05, 2011

Flex3 Localization

http://www.herrodius.com/blog/123


1. create a folder in your project src to store your resource bundles (e.g. "locale")
2. create a subfolder for each locale you want to implement (e.g. "locale\en_US" and "locale\zh_TW")
3. in the locale subfolder, create a resources.properties file and save it as UTF-8
4. enter the resources in the form of "key=value", like Ant property files
example:

# locale/en_US/resources.properties
login_id=id
password=password

5. update the compiler settings: -locale=en_US,zh_TW -source-path=locale/{locale}


[ResourceBundle("resources")]



< mx:FormItem label="{resourceManager.getString('resources', 'login_id')}" ....


switch your locale at runtime by setting the localeChain property on the resourceManager:

resourceManager.localeChain = ["en_US"];
//resourceManager.localeChain = ["zh_TW"];


Set focus on textfield in Flex3

In Action Script:
login.setFocus();

In HTML:






< body onload="setFlexAppFocus();">


2. detect press Enter
   

/**
* Handle login when user press enter on password
*/
private function enterListener(e:KeyboardEvent):void {
if(e.keyCode == Keyboard.ENTER) {
enter(); // check login function
}
}

星期五, 11月 05, 2010

利用 vb.net 偵測全域的滑鼠及鍵盤動作

使用windowshooklib

http://www.vbforums.com/showthread.php?t=436321


http://www.code2point.com/Project.aspx?proj=4

使用方法就是下載其 WindowsHookLib.dll , 在 .net 專案中加入此參考,





Imports WindowsHook

Public Class Form1
Dim WithEvents mHook As New MouseHook

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
'Install the mouse hook
mHook.InstallHook()
Catch ex As Exception
MessageBox.Show("Failed to install the mouse hook!." _
& Environment.NewLine & ex.Message, "Hook Error!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
'Remove the mouse hook
mHook.RemoveHook()
Catch ex As Exception
MessageBox.Show("Error removing the mouse hook!." _
& Environment.NewLine & ex.Message, "Hook Error!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End Sub

Private Sub mHook_MouseDown(ByVal sender As Object, ByVal e As WindowsHook.MouseEventArgs) Handles mHook.MouseDown
'Set the Handled property for the mouse down event
'to block the mouse down message for the
'controls that are not in the alowedList.
'e.Handled = Not Me.alowedList.Contains(CType(sender, IntPtr))
'Do some other things here
'...
'Me.TextBox1.Text = "mouse down"
Me.TextBox1.Text = e.Button.ToString
'...
End Sub
End Class


星期三, 7月 14, 2010

半形轉全形 (php)




function n_to_w($strs, $types = '0'){ // narrow to wide , or wide to narrow
$nt = array(
"(", ")", "[", "]", "{", "}", ".", ",", ";", ":",
"-", "?", "!", "@", "#", "$", "%", "&", "|", "\\",
"/", "+", "=", "*", "~", "`", "'", "\"", "<", ">",
"^", "_",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z",
" "
);
$wt = array(
"(", ")", "〔", "〕", "{", "}", "﹒", ",", ";", ":",
"-", "?", "!", "@", "#", "$", "%", "&", "|", "\",
"/", "+", "=", "*", "~", "、", "、", """, "<", ">",
"︿", "_",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z",
" "
);

if ($types == '0'){
// narrow to wide
$strtmp = str_replace($nt, $wt, $strs);
}else{
// wide to narrow
$strtmp = str_replace($wt, $nt, $strs);
}
return $strtmp;
}

台北城中扶輪社網址

台北城中扶輪社
Rotary Club of Taipei Castle
www.taipei-castle.org.tw

星期二, 6月 22, 2010

超肥的Microsoft Office 輸入法 2010

真是厲害, 輸入法竟然能搞到 131.2 MB

星期二, 9月 15, 2009

Using MD5 in C language




http://mixtt.blogspot.com/2009/06/c-using-md5-in-c-language.html





#include <openssl/md5.h>
/*Encode str to str_enc using md5 algorithm*/
void md5(char *str, char *str_enc) {
int i = 0;
unsigned char d[16];
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update (&ctx, (char *) str, strlen(str));
MD5_Final(d, &ctx);
for (i = 0; i < 16; i++) {
sprintf(str_enc + (i*2), "%02X", d[i]);
}
str_enc[32] = 0;
}

Use C language to get MAC Address in linux





#include <stdio.h>
#include <string.h> /* for strncpy */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>

int main(void) {
int fd;
struct ifreq ifr;

char mac[20];
fd = socket(AF_INET, SOCK_DGRAM, 0);

ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1);

ioctl(fd, SIOCGIFHWADDR, &ifr);

close(fd);

sprintf(mac,"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
(unsigned char)ifr.ifr_hwaddr.sa_data[0],
(unsigned char)ifr.ifr_hwaddr.sa_data[1],
(unsigned char)ifr.ifr_hwaddr.sa_data[2],
(unsigned char)ifr.ifr_hwaddr.sa_data[3],
(unsigned char)ifr.ifr_hwaddr.sa_data[4],
(unsigned char)ifr.ifr_hwaddr.sa_data[5]);

printf("eth0 mac address:%s\n", mac);

return 0;
}

星期一, 5月 11, 2009

Asterisk 整合 gtalk

gtalk.conf =>
[buddy]
username=xxx@gmail.com
disallow=all
allow=ulaw
context=google-in ;order apparently matters, needs to be placed after username= ?
connection=gtalk_account

jabber.conf =>
[gtalk_account]
type=client
serverhost=talk.google.com
username=yyy@gmail.com/Talk ;; Astersk 的 gtalk 分身,必須要有此帳號
secret=zzz ;; yyy@gmail.com 的密碼
port=5222
usetls=yes ; TLS is required by talk.google.com, you'll get a 'socket read error' without
usesasl=yes
buddy=xxx@gmail.com
buddy=aaa@gmail.com
statusmessage="From Miles Blogger"
timeout=100

;; 從 Asterisk 分機撥給 gtalk 帳號 xxx@gmail.com
;; 會從yyy@gmail.com 撥給 xxx@gmail.com

dialplan =>
exten => 888,1,NoOp(+++ Dial to xxx@gmail.com +++)
exten => 888,n,Dial(Gtalk/gtalk_account/xxx@gmail.com)
exten => 888,n,Hangup

從 xxx@gmail.com 撥給 yyy@gmail.com 會轉到 Asterisk 的 dialplan 中的
[google-in] 裡面


更多的詳情可參看:
http://www.voip-info.org/wiki/view/Asterisk+Google+Talk

星期四, 4月 30, 2009

Asterisk 整合 VoiceXML

VoiceGlue
http://www.voiceglue.org/

安裝說明
http://voiceglue.org/wiki/doku.php?id=voiceglue_0.9_installation_instructions

因為我是用Gentoo , 所以只好使用困難的安裝方法 :-)
經過一番努力安裝完成後,接著就看設定部分
http://voiceglue.org/wiki/doku.php?id=voiceglue_0.9_user_guide

測試的 Dialplan 為
exten => 6666,1,NoOp("++++ Test voiceglue +++")
exten => 6666,n,Answer
exten => 6666,n,AGI(agi://localhost/url=http%3A%2F%2Flocalhost%2Fvxml%2Fhello.vxml)
exten => 6666,n,Hangup


http://localhost/vxml/hello.vxml 內容為

(vxml version="2.0" xmlns="http://www.w3.org/2001/vxml")
(form)
(block)
(prompt)
Welcome
(/prompt)
(/block)
(/form)
(/vxml)


voiceglue 預設是使用 flite 做為 TTS,
我們可以將其改用 espeak ,使其支援中文,方法如下:
修改 voiceglue_tts_gen
將其內容改為
system ("espeak", "-s 120", "-v", "zh", "-w", $file, "\"".$ARGV[1]."\"");
system ("mv", $file, $file . ".16khz.wav");
system ("sox", $file . ".16khz.wav", "-r", "8000", $file);
system ("rm", "-f", $file . ".16khz.wav");

就是這麼簡單 :-)

試著將 http://localhost/vxml/hello.vxml
中的 Welcome 改成中文,就可以聽到中文的語音囉

PS: 網頁必須是 UTF8 格式

Asterisk & 中文 TTS

espeak
http://espeak.sourceforge.net/
有支援中文的 TTS

asterisk-espeak is a eSpeak text-to-speech module for the Asterisk open-source PBX
http://asterisk-espeak.sourceforge.net/

若是用 asterisk 1.6.x 的版本,可參考以下的說明 patch
http://www.mail-archive.com/openpkg-cvs@openpkg.org/msg21782.html


記得要在 espeak.conf 設定
voice=zh
如此才會正確的處理中文


正確 install 成功後,測試的 Dialplan 如下
exten => 900,1,NoOp("+++++ Test espeak ++++")
exten => 900,n,Answer
exten => 900,n,espeak(測試中,你好,歡迎使用 asterisk |any)
exten => 900,n,Hangup


PS: 中文必須使用 UTF8 格式

星期一, 5月 28, 2007

Asterisk extensions.conf (二)

extensions.conf

設計撥號規則 (二)
-----------------------------------------------------------------
通常我們會將 extensions.conf 切分成好幾個檔,
然後再 include 進來 , 這樣比較好做規劃

例如: 將從 FXO 進線的撥號規則存入 fxo_incoming.conf ,
從 SIP 進線的撥號規則存入 sip_incoming.conf

在 extensions.conf 中 , 就可以用
;;; For fxo incoming
#include fxo_incoming.conf
;;; For sip incoming
#include sip_incoming.conf
將其檔案 include 進來 , 另外要注意的是有另一種 include ,
是 include context , 而非 include 檔案

例如在 extensions.conf 中

[test_context]
exten => 1234,1,Answer
.....
.....
;;; include context : test2_context
include test2_context

[test2_context]
exten => 2345,1,Answer
....
....

即表示 context [test_context] , 包括 [tests_context] 這個 context 內容
亦即 context [test_context] 設定為
exten => 1234,1,Answer
.....
.....
exten => 2345,1,Answer
....
....

--------------------------------------------------------------------------------
Asterisk 使用以下特殊用途 extension 名稱:

* i : 使用者按下沒有定義的 extension 號碼
* s : Start extension in context
* h : Hangup extension
* t : Timeout extension
* T : AbsolutTimeout() extension
* o : Operator extension, used for operator exit by pressing zero in voicemail
--------------------------------------------------------------------------------
Macro (巨集)
範例:
Using a macro to create extensions
[globals]
PHONE1=Zap/1
PHONE2=SIP/6002

;;; Macro(oneline,${PHONE1},${PHONE2},${PHONE3}....)
;;; ${ARG1} 就等於 ${PHONE1} , ${ARG2} 就等於 ${PHONE3} 依此類推 ...
[macro-oneline]
exten => s,1,Dial(${ARG1},20,t)
exten => s,2,Voicemail(u${MACRO_EXTEN})
exten => s,3,Hangup
exten => s,102,Voicemail(b${MACRO_EXTEN})
exten => s,103,Hangup

[local]
exten => 6601,1,Macro(oneline,${PHONE1})
exten => 6602,1,Macro(oneline,${PHONE2})

星期三, 5月 23, 2007

Asterisk extensions.conf (一)

Asterisk 可說是目前當紅的 open source IP PBX
詳細說明可至 http://www.voip-info.org/wiki/view/Asterisk 查看

接下來將會以我所知來說明 Asterisk 的設定與運用

extensions.conf

設計撥號規則

內容如下:

;;;撥號規則的環境變數
[general]
;;;預設為 no
static=yes
;;;預設為 no , 如果 writeprotect=no 且 static=yes , 則當在 CLI command 模式中, 執行 save dialplan,
;;;將會儲存目前的撥號規則設定
writeprotect=yes
;;;如果設定為 yes , 則系統將會依據其判斷猜測其為 BUSY,CONGENSTION或HANGUP而終止通話斷線,強烈建議設定為yes
autofallthrough=yes
;;;若設定為 yes, 則執行 extensions reload 時 , 將會清除通用變數的資料
clearglobalvars=no
;;;
priorityjumping=no

;;;撥號規則的通用變數
[globals]
;;; 設定 INCOMING 變數等於 Zap/3&Zap/4
;;; 於撥號規則內可用 ${INCOMING} 來運用 (變數名稱不分大小寫 , 也就是 ${INCOMING} 相當於 ${incoming})
INCOMING => Zap/3&Zap/4
;;; 撥號規則是由一推的 contexts 所組成 , 每一個 context 由一推的 extensions 組成
;;; 例如以下: [sip_outgoing] 即是一個 context
[sip_outgoing]
;;; exten = extension,priority,Command(parameters) (使用 = 或 => 都可以)
extension => 123,1,Answer
extension => 123,2,Dial(SIP/456,30)
extension => 123,3,Hangup
;;; Pattern , 在 extension 中第一個字為 _ 時 , pattern 才有作用
;;; X 表示 0 至 9
;;; Z 表示 1 至 9
;;; N 表示 2 至 9
;;; [1237-9] 表示 1,2,3,7,8,9
;;; . 表示一個或多個任意字
;;; ! 表示 0 個或多個任意數
;;; 例如以下表示所有 4 位數字的都符合
extension => _XXXX,1,Answer
extension => _XXXX,2,Dial(SIP/567,30)
extension => _XXXX,3,Hangup

星期一, 4月 16, 2007

mysql 雙向 replication

mysql Replication
-----------------------------
1. 兩台主機的 mysql 設定檔
my.cnf
加上
;;server-id = 2
server-d =1
log-bin
binlog-do-db = db1
binlog-do-db = db2
binlog-do-db = db3
binlog-do-db = db4
;;master-host = 192.168.1.22
master-host = 192.168.1.30
master-user = ruser
master-password = rpass
master-port = 3306
master-connect-retry = 60
replicate-do-db = db1
replicate-do-db = db2
replicate-do-db = db3
replicate-do-db = db4

2. 兩台主機新增帳號
***** For 4.0.x 以前版本
grant file on *.* to ruser@192.168.1.22 identified by 'rpass';
grant file on *.* to ruser@192.168.1.30 identified by 'rpass';
***** For 4.1.x 以後版本
grant replication slave on *.* to ruser@192.168.1.22 identified by 'rpass';
grant replication slave on *.* to ruser@192.168.1.30 identified by 'rpass';

3. 修改 /etc/hosts.allow
mysqld: 127.0.0.1 192.168.1.22 192.168.1.30

4. 清除 bin-log 檔
設定使用 ssh 直接登入其它伺服器 , 不需要認證
在 192.168.1.22主機上執行
ssh-keygen -t rsa
不要輸入密碼, 產生 RSA key
cat /root/.ssh/id_rsa.pub
將內容複製起來 , 然後在 192.168.1.30 主機上 , 加入 /root/.ssh/authorized_keys 存檔

同樣動作 192.168.1.30 也做一次

如此在 192.168.1.22 主機上執行 ssh 192.168.1.30 , 即可直接登錄
同理在 192.168.1.30 主機上執行 ssh 192.168.1.22 也可直接登錄


新增一檔案 purge_replication_log.sh , 內容如下:

#!/usr/bin/env bash
#######################################################
# Initialization: define variables in need
#######################################################
PATH=/usr/local/bin:/usr/bin:/bin
USER="root"
PASSWD="rootpassword"
CMDSLAVE="stop slave;reset slave;start slave;"
CMDMASTER="reset master;"
MASTER="192.168.1.22"
SLAVE="192.168.1.30"
#### clean master bin-log and slave restart slave
(mysql -u$USER -p$PASSWD -e "$CMDMASTER") 1>/dev/null
(ssh $SLAVE "mysql -u$USER -p$PASSWD -e \"$CMDSLAVE\"") 1>/dev/null
### claen slave bin-log and master restart slave
(ssh $SLAVE "mysql -u$USER -p$PASSWD -e \"$CMDMASTER\"") 1>/dev/null
(mysql -u$USER -p$PASSWD -e "$CMDSLAVE") 1>/dev/null
exit 0


如此 , chmod 755 purge_replication_log.sh
定期執行 purge_replication_log.sh 即可將 bin-log 刪除 , 以防 bin-log 過大 , 並保持雙向同步

星期二, 11月 01, 2005

眼睛視網膜病變

最近眼睛右眼看東西, 正中間都有一團黑影 , 導致東西都看不清楚 ,
至醫院檢查 , 發現是視網膜病變所引起 , 需要長期休息及作進一步檢查.
原因可能是愛情動作片看太多了 , ㄚ~ 不是啦 , 醫生說應該是壓力大 , 且
太長時間看電腦螢幕所引起的 .

目前正在家休養中 , 可能會休息一兩個月吧~~ 大家努力
工作之餘 , 更要保重身體啊~~

星期五, 9月 02, 2005

在asp.net中處理意外情況

於Global.asax 中的 Application_Error 事件加上以下的內容 , 如此
當系統發生意外情況時 , 則會將錯誤訊息 mail 給指定的人 , 並將網頁導至
Maintenance.aspx

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' 發生錯誤時引發
If (System.Web.HttpContext.Current.Request.Url.Authority <> "localhost") Then
''' Get the Exception object wrapped in the InnerException property
Dim unhandledException As Exception = Server.GetLastError().InnerException
''' Create a MailMessage
Dim mail As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mail.From = "error@abc.com"
mail.To = "admin@abc.com"
mail.BodyFormat = System.Web.Mail.MailFormat.Text
mail.Subject = "unHandledException.Message"
mail.Body = unhandledException.ToString()
System.Web.Mail.SmtpMail.SmtpServer = "127.0.0.1"
''' Send the email
System.Web.Mail.SmtpMail.Send(mail)
''' Redirect the user to a maintenence page
System.Web.HttpContext.Current.Response.Redirect("Maintenance.aspx")
End If
End Sub