星期日, 2月 10, 2013

思念

咫尺天涯, 是因為心不在一起, 天涯咫尺卻是因為思念.

不在思念的家裏, 就是在往思念的路上.
真正的思念是無法短時間內停止下來, 只能讓時間來慢慢沖淡,
但也只能淡化, 將此思念轉換成另一種感覺, 變成自己可以承受的型態,
它有時會藏在口袋裡, 有時會躲在你喜愛的食物裡, 有時會隱身在你的書裡,
偶爾會出來刺你一下, 但此時你將已習慣此柔軟的刺痛.

星期二, 1月 22, 2013

Resizing Video SurfaceView on Android


 http://clseto.mysinablog.com/index.php?op=ViewArticle&articleId=2992625

1.     surfaceView.getHolder().setFixedSize(width, height);
        surfaceView.requestLayout();
        surfaceView.invalidate();     // very important, so that onMeasure will be triggered

2.    Layout XML:
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"

星期三, 11月 07, 2012

use intent to share media to YouTube or Facebook

    private void share_media(String outputFile){
        // first check if the outputFile is exists
        if (!new File(outputFile).isFile()){
            return;
        }
        ContentValues content = new ContentValues(4);
        content.put(Video.VideoColumns.TITLE, "My Test");
        content.put(Video.VideoColumns.DATE_ADDED,
        System.currentTimeMillis() / 1000);
        content.put(Video.Media.MIME_TYPE, "video/mp4");
        content.put(MediaStore.Video.Media.DATA, outputFile);
        ContentResolver resolver = getContentResolver();
        Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
     
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("video/*");
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        try {
            startActivity(Intent.createChooser(intent, "Share using"));       
        }
        catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(getApplicationContext(),"No way to share",Toast.LENGTH_LONG).show();
        }
        return;
    }

星期二, 11月 06, 2012

Convert Side by Side image to Blue & Red 3D stereo mode

Convert Side by Side image to Blue & Red 3D stereo mode           

Bitmap dst = null;
int w = src_bitmap.getWidth();
int h = src_bitmap.getHeight();
int [] dst_pixs = new int[w * h];
int[] left_pixs;
int[] right_pixs;
int alpha;
int r;
int g;
int b;
// fix if width or height is odd will cause crash
if (w % 2 == 1){
    w = w-1;
}
if (h % 2 == 1){
    h = h-1;
}
//
int totals = w * h;

left_pixs = new int[(w / 2) * h];
right_pixs = new int[(w / 2) * h];
// Get Left and Right Pixs
src.getPixels(left_pixs, 0, w/2, 0, 0, w/2, h);
src.getPixels(right_pixs, 0, w/2, w/2, 0, w/2, h);
//
dst = Bitmap.createBitmap(w, h, Config.ARGB_8888);

for (i = 0; i < totals - 1; i++) {
                // Convert color , For blue & red ==> (left.a, left.r, right.g, right.b)
                alpha = left_pixs[i/2] & 0xff000000;
                r = (left_pixs[i/2] >> 16) & 0xff;
                g = (right_pixs[i/2] >> 8) & 0xff;
                b = right_pixs[i/2] & 0xff;
                dst_pixs[i] = alpha | (r << 16) | (g << 8) | b;
                // end conver color  
 }
dst.setPixels(dst_pixs, 0, w, 0, 0, w, h);

星期日, 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})