QR Code 印章
04/22/2010, 22:46 - Misc
最近都在研究 QR Code 的演算法,想想就去刻印行製作了一個小印,當作藏書印。事實上也很簡單,將圖檔傳給刻印行,說明尺寸及材質,一天就可以拿到了,我作的這顆收我40元啦。要產生圖檔網路上找一下就有了,要解碼的話,可以拿到的就更多了,可以裝在手機、電腦、iPhone、Notebook...。印在紙上,可以解碼沒有問題,只要印泥不要太多,不要用力,就可以了。用什麼顏色的印泥都可以,不過對比色高一點比較好辦認。

原始圖檔


印章掃描



2 回應 2 回應 ( 142預覽 )   |  [ 0 引用 ]   |  permalink   |   ( 3.5 / 6 )

用 Expect 連接 RS-232 及 telnet
12/31/2009, 16:50 - Misc
expect 可以模擬和程式或設備溝通, 是很方便的小工具, 使用 tcl script language, 可以用在 rs-232, telnet, ftp 等等, 將需要人操作的程式自動化. 可以在 Windows/Linux/BSD/Solaris/Mac OS X ...上使用.

用 expect 連接 RS-232 自動在人機介面模擬人按鍵, 作自動測試.

#!/usr/bin/expect --
# add -d for expect dump debug message
#
proc startUp x {
send " "
send " "
sleep 1
return
}

proc backSpace x {
# Send 8 backspace key code
send \177\177\177\177\177\177\177\177
sleep 1
return
}

proc loopbackTest x {
set y $x
set timeout 3
# 0x28 is down arrow keycode
if {$y eq 0} {
send \x28
sleep 1
set timeout 1
expect {
STU-C-I/F {
send " "
send "\r"
}
STU-C-DSL {
send "\r"
}
STU-R-DSL {
send " "
send " "
send " "
send "\r"
}
STU-R-I/F {
send " "
send " "
send "\r"
}
timeout {
send " "
send " "
send " "
send "\r"
}
}

# 0x28 is down arrow keycode
send \x28
sleep 1
}

set timeout 30

while {$y ne 0} {
expect {
underflow {
puts "\n\nRun $y Times\x07\n\n"
exit $y
}
Network {
send "\r"
}
Customer {
sleep 1
}
Off {
send "\r"
}
Download {
send "\x07"
exit
}
timeout {
send " "
}
}
incr y
}
## Rescursive test
incr y
loopbackTest $y
return
}

proc carrigeReturn x {
# Carrige Return 0x13 "\r"
send "\r"
sleep 1
return
}

proc passwordKeyin x {
expect {
assword: {
# press enter as password
carrigeReturn 0
}
Test {
# Goto Test menu
send T
sleep 1
# Goto Loopback Test
loopbackTest 0
return
}
again {
# Password error, send Enter to try again
carrigeReturn 0
}
loopbacks {
# Send Escape key to escape to main menu
send \033
sleep 1
# Goto Test menu
send T
sleep 1
# Goto Loopback Test
loopbacktest 0
return
}
"Clear 24 Hour History" {
# It must in Main Menu, Escape
send \033
sleep 1
}
Download {
puts "\x07"
exit
}
timeout {
# Nothing, send backspace and enter for renew screen display
backSpace 0
sleep 1
send "\r"
sleep 1
}
}
}

# Set default timeout
set timeout 10
# Set Serial port parameters
set port [open /dev/tts/USB0 RDWR]
fconfigure $port -blocking 0 -buffering line -mode 9600,n,8,1 -translation auto
-eofchar {}

# Start connect from serial port
uplevel #0 {spawn -open $port}

#set session1 $spawn_id

# wait for connected
sleep 2

# Send 2 space for calculate connection speed from client
startUp 0
#
set x 0
while {$x eq 0} {
passwordKeyin 0
}
#passwordKeyin 0
#passwordKeyin 0

#close serial port
close $port
#End


用 expect 連接 Telnet 並按鍵

#!/usr/bin/expect -d

set timeout 3

spawn telnet 172.16.7.250

while {$timeout ne 0} {
expect {
4.SW4 {
expect {
timeout {
send "4\r"
}
}
}
timeout {
send "0"
}
}
}


發表回應 發表回應 ( 293預覽 )   |  [ 0 引用 ]   |  permalink   |   ( 3 / 26 )

Terminal Characters define
12/21/2009, 12:31 - Misc
000 0 0x00 NUL
001 1 0x01 SOH, Control-A
002 2 0x02 STX, Control-B
003 3 0x03 ETX, Control-C
004 4 0x04 EOT, Control-D
005 5 0x05 ENQ, Control-E
006 6 0x06 ACK, Control-F
007 7 0x07 BEL, Control-G
010 8 0x08 BS, backspace, Control-H
011 9 0x09 HT, tab, Control-I
012 10 0x0a LF, line feed, newline, Control-J
013 11 0x0b VT, Control-K
014 12 0x0c FF, form feed, NP, Control-L
015 13 0x0d CR, carriage return, Control-M
016 14 0x0e SO, Control-N
017 15 0x0f SI, Control-O
020 16 0x10 DLE, Control-P
021 17 0x11 DC1, XON, Control-Q
022 18 0x12 DC2, Control-R
023 19 0x13 DC3, XOFF, Control-S
024 20 0x14 DC4, Control-T
025 21 0x15 NAK, Control-U
026 22 0x16 SYN, Control-V
027 23 0x17 ETB, Control-W
030 24 0x18 CAN, Control-X
031 25 0x19 EM, Control-Y
032 26 0x1a SUB, Control-Z
發表回應 發表回應 ( 342預覽 )   |  [ 0 引用 ]   |  permalink   |   ( 2.8 / 33 )

SED recursive strip
12/14/2009, 11:48 - Misc
This is a script to recursive strip some thing between "$A_PROPERTIES" and "$FUNCTIONS" also between "$FUNCTIONS" to "$NETS"
And strip all of the ":FXX." to "."


#!/bin/sh
sed -e "s/\:F[0-9]*\./\./g" $1 >$1.txt
sed -e "/^\$A_PROPERTIES/,/^\$FUNCTIONS/!b
/^\$A_PROPERTIES/{
x
s/^.*\n//
x
}
G
/\$FUNCTIONS/!d
s/\n.*//
" $1.txt >$1.txt.txt

sed -e "/^\$FUNCTIONS/,/^\$NETS/!b
/^\$FUNCTIONS/{
x
s/^.*\n//
x
}
G
/\$NETS/!d
s/\n.*//
" $1.txt.txt >$1.txt

rm -fr $1.txt.txt



發表回應 發表回應 ( 224預覽 )   |  [ 0 引用 ]   |  permalink   |   ( 3.2 / 33 )

更新已讀書目
02/08/2009, 18:57 - Misc
更新已讀書目
發表回應 發表回應 ( 242預覽 )   |  [ 0 引用 ]   |  permalink   |   ( 3 / 78 )

How to optimization loop in programming
02/22/2008, 11:28 - Misc
If some guy ask you to tune the program with a simple function add from 0 to 100,
how to optimization the execution speed ?
in normal we will program as under :

for(i=0;i<=100;i++)
j+=i;

but it is the fast way ?
try under to see what happen.
The program is add from 0 to 100000000 and get the result, and spent CPU's clock.


#include <stdio.h>
#include <time.h>
#include <sys/times.h>
void main(void)
{
register long int i1,i2,i3,i4,i5,i6,i7,i8;
register long int j;
register long int k=100000000;
clock_t c1,c2;

/* Single loop */
j=0;
c1=clock();
for(i1=0;i1<=k;i1++)
j+=i1;
c2=clock();
printf("Result=%d Clock=%d\n",j,c2-c1);

/* Dual loop */
j=0;
c1=clock();
for(i1=1,i2=k;i1<=k/2;i1++,i2--)
j=j+i1+i2;
c2=clock();
printf("Result=%d Clock=%d\n",j,c2-c1);

/* Quad loop */
j=0;
c1=clock();
for(i1=1,i2=(k/4)+1,i3=(k/2)+1,i4=k;i1<=k/4;i1++,i2++,i3++,i4--)
j=j+i1+i2+i3+i4;
c2=clock();
printf("Result=%d Clock=%d\n",j,c2-c1);

/* Eighth loop */
j=0;
c1=clock();
for(i1=1,i2=(k/8)+1,i3=((k/8)*2)+1,i4=((k/8)*3)+1,i5=((k/8)*4)+1,i6=((k/8)*5)+1, \
i7=((k/8)*6)+1,i8=k;i1<=k/8;i1++,i2++,i3++,i4++,i5++,i6++,i7++,i8--)
j=j+i1+i2+i3+i4+i5+i6+i7+i8;
c2=clock();
printf("Result=%d Clock=%d\n",j,c2-c1);
}

Result is:

Result=987459712 Clock=290000
Result=987459712 Clock=220000
Result=987459712 Clock=160000
Result=987459712 Clock=140000


So we can found that separate to more pieces will get more speed. the last result separate to 8 loop, and got only the original loop's half time, but it required more code and mode space.

發表回應 發表回應 ( 246預覽 )   |  [ 0 引用 ]   |  permalink   |   ( 3.1 / 140 )

Google Desktop for Linux
08/02/2007, 12:27 - Misc
Install Google Desktop for Linux to get better and easy use search engine than Beagle.

But there are not support for Slackware Linux, so I download the rpm file and install it with command "rpm -i --nodeps ..." to skip some dependance check. After installed, mv the to /usr/google from /opt/google and change the script /usr/google/desktop/bin/gdlinux to currect path setting inside the script, then go and start indexing, approx need 67 hours for my disk 175 GB information to indexing.
發表回應 發表回應 ( 213預覽 )   |  [ 0 引用 ]   |  permalink   |   ( 3.1 / 300 )

Linux Acrobat reader expr: syntax error with gtk-2.11.1
06/05/2007, 14:34 - Misc
The Linux Acrobat reader has expr: syntax error cause can not run, is an old problem, and the solution will be found at Fix Adobe Acrobat Reader’s “expr: syntax error” message

It work fine, before I update the gtk to 2.11.1,
so, after some research, I found that is because the /usr/lib/libgtk-x11 version change cause the problem.

The original acroread is a executable shell script at /usr/bin with virtual link to Acrobat install directory, in my is locate at /usr/Acrobat7.0/bin ,
and the libgtk-x11 is locate at /usr/lib

but, when list the libgtk-x11, I got many version of it, because I upgraed the gtk offen.

libgtk-x11-2.0.so.0.1000.10
libgtk-x11-2.0.so.0.1000.11
libgtk-x11-2.0.so.0.1000.12
libgtk-x11-2.0.so.0.1000.2
libgtk-x11-2.0.so.0.1000.3
libgtk-x11-2.0.so.0.1000.4
libgtk-x11-2.0.so.0.1000.5
libgtk-x11-2.0.so.0.1000.6
libgtk-x11-2.0.so.0.1000.7
libgtk-x11-2.0.so.0.1000.9
libgtk-x11-2.0.so.0.1100.0
libgtk-x11-2.0.so.0.1101.0
libgtk-x11-2.0.so.0.600.10


so the script did not match the newest libgtk-x11 library cause run time error.

I patch the acroread as:

--- acroread.backup 2007-06-05 14:26:29.000000000 +0800
+++ acroread 2007-06-05 14:30:02.000000000 +0800
@@ -415,7 +415,8 @@ get_gtk_file_ver()
return 1
fi

- echo $mfile| sed 's/libgtk-x11-\([0-9]*\).0.so.0.\([0-9]*\)00.\(
[0-9]*\)\|\(.*\)/\1\2\3/g'
+# echo $mfile| sed 's/libgtk-x11-\([0-9]*\).0.so.0.\([0-9]*\)00.\(
[0-9]*\)\|\(.*\)/\1\2\3/g'
+ echo $mfile| sed 's/libgtk-x11-\([0-9]*\).0.so.0.\([0-9]*\)0\([0-9]\).\(
[0-9]*\)\|\(.*\)/\1\2\3/g'
return 0
fi


result the problem, but when next time I upgrade the gtk, it maybe will come out, because the libgtk-x11 version change again. Anyway, the acrobat reader is work now.

發表回應 發表回應 ( 285預覽 )   |  [ 0 引用 ]   |  permalink   |   ( 3 / 289 )

VMWare 6 for Linux and USB enable
05/17/2007, 16:56 - Misc
Since upgrade from VMWare 5.5.3 to VMWare 6 on Slackware Linux 11,
The Virtual machine is be required to upgeade to version 6 for USB 2.0, but after upgrade, the VMWare still can not found any USB device, but the USB device work fine under Linux.

Long time for try and dig on net what ever the VMWare forum or google, got no answer. So I start return to VMWare's User manual, at least found in that pdf file, page 355 has some note for Linux:

Using USB with a Linux Host

On Linux hosts, VMware Workstation uses the USB device file system to connect to
USB devices. In most Linux systems that support USB, the USB device file system is at
/proc/bus/usb.
If your host operating system uses a different path to the USB device file system, run
the following command as root to mount the file system to the expected location:
mount -t usbfs none /proc/bus/usb
If you attach a USB drive to a Linux machine, use the above‐mentioned procedure to
access it. Do not attempt to add a USB drive’s device node (for example, /dev/sda)
directory to the virtual machine as a hard disk. That is, to add a USB drive, use the Add
Hardware wizard to add a USB Controller, not a hard disk.


After follow this step, I got the USB work for VMWare again! so put this line into /etc/fstab is very good idea!
add under to /etc/fstab

none /proc/bus/usb usbfs auto,devmode=0666 0 0


Also reference to
http://solutions.brother.com/linux/sol/ ... stall.html
發表回應 發表回應 ( 1300預覽 )   |  [ 0 引用 ]   |  permalink   |   ( 3 / 287 )

Good Programmer is Lazy
05/02/2007, 19:02 - Misc
在 Google Video Code Generation with Ruby中講者 Jack HerringtonGood Programmer is Lazy破題,作為開場,先不管這場講的內容,光是這個開場,就很有道理。
一個程式設計人員,通常被要求要快、要準確的作出要求的程式,但是現在很多的程式設計人員,並這並不存在真實的世界中,至少我沒有真正遇到。要作出一個好的程式,通常要先作好分析,並規劃,最後才產生出程式。但是現在的程式設計人員,大都是看到要求之後,就打開電腦,直接寫程式,並一邊試,一邊修改,完全沒有想過完整的流程,認為那是學校教的方法,並不實用。事實上,是因為不知道如何下手,才會只有邊試邊改,最好是有現成的可以 Copy and Paste。而在 Time to market 的最高指導原則下,草草揮就,可以執行、不會當機,工作效率還可以接受的程式。這樣是懶,但是說到是好的程式設計人員,還早得很,充其量是“爛“的程式抄寫人員而己。

一個懶的好程式設計師是知道如何以最少的時間、最少的程式碼、以及最快寫出需求的程式,還有就是最少的 bug,以及好的程式效率。但這樣子不是要花很多時間嗎?不一定。在開始寫程式之前,若有用心花時間研究,並好好的規劃,產生出程式,只是中間的一個小小步驟而己,而好的規劃大都可以在一次至二次的 debug 過程中完成一個高水準的程式,其他時間可以用來作別的事。在別人的眼中看來,就可能是沒事作,或是不專心在工作上,才會認為這是一個懶人。而真正好的程式設人員,是會善用工具及利用工具來解決問題,最好是保時自己的一份程式庫,並時時修訂,加強效率。有時利用 open source 的工具,如 lex/yacc/sed/awk/shell script/perl ,利用程式來產生程式,增加生產力。而不是一味的利用抄襲、修改、測試的方式來產生程碼。當然抄別人的程式片段,並不是不好的事,但是不是完全的抄,而是經過細心規劃及研究後,使用別人的程式碼作為工具。要懶之前,要先努力找出可以懶的的方法。用電腦是要解決問題,令人生活得更懶,而不是一天二十小時坐在電腦之前,用力 Copy and Paste,以及 Try and Run 。

2 回應 2 回應 ( 195預覽 )   |  [ 0 引用 ]   |  permalink   |   ( 2.9 / 337 )


| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 下一頁> 最後>>