2011年1月12日星期三
ubuntu 下 用wine utorrent來抓magnet url
gconftool-2 -s /desktop/gnome/url-handlers/magnet/needs_terminal false -t bool
gconftool-2 -t bool -s /desktop/gnome/url-handlers/magnet/enabled true
記得要改自己的utorrent位置呀
2010年12月8日星期三
總結 eeepc t91 安裝gma 500 與touch screen 所需的code
sudo add-apt-repository ppa:gma500/ppa && sudo apt-get update
sudo apt-get install poulsbo-driver-2d poulsbo-driver-3d poulsbo-config
修正 touch screen:
xinput list
找出IDEACOM IDC 6680 的id
sudo gedit /etc/X11/Xsession.d/98x11-common_touchscreen
xinput set-int-prop 8 "Evdev Axis Calibration" 32 300 7900 400 7800
把8改為你找到的id
2010年10月2日星期六
optimize jquery selector
- ';
- item ';
for (i=0; i<1000; i++) {
items += '
}
items += '
var list = $('#list');
list.html(items);
console.time('direct');
for (i=0; i<10000; i++) {
var s = $('.item');
}
console.timeEnd('direct');
console.time('Specific tag');
for (i=0; i<10000; i++) {
var s = $('li.item');
}
console.timeEnd('Specific tag');
console.time('Specific class');
for (i=0; i<10000; i++) {
var s = $('.item.anotherClass');
}
console.timeEnd('Specific class');
console.time('Specific another class');
for (i=0; i<10000; i++) {
var s = $('li.item.anotherClass');
}
console.timeEnd('Specific another class');
console.time('with ancestor');
for (i=0; i<10000; i++) {
var s = $('#ulId .item');
}
console.timeEnd('with ancestor');
console.time('with context');
for (i=0; i<10000; i++) {
var s = $('.item','#ulId');
}
console.timeEnd('with context');
console.time('specific tag with context');
for (i=0; i<10000; i++) {
var s = $('.item','#ulId');
}
console.timeEnd('specific tag with context');
console.time('direct with jquery context');
for (i=0; i<10000; i++) {
var s = $('.item',$('#ulId'));
}
console.timeEnd('direct with jquery context');
得出
direct: 3791ms
Specific tag: 3483ms
Specific class: 4128ms
Specific another class: 3001ms
with ancestor: 3094ms
with context: 72ms
specific tag with context: 73ms
direct with jquery context: 75ms
最緊要係加context!
2010年9月1日星期三
Ubuntu 10.04 上, 定時用ClamAV 掃毒並 email log
$ sudo apt-get install clamav
更新病毒庫
$ sudo freshclam
設定cron
$ sudo vim /usr/local/bin/virus_scan.sh
#!/bin/bash
# ----------------------------------------------------------------------
# Virus scan with ClamAV
# ----------------------------------------------------------------------
# Disabling PATH improves the security of the script
unset PATH
# Declare the variables
ECHO=/bin/echo;
DATE=/bin/date;
FRESHCLAM=/usr/bin/freshclam;
CLAMSCAN=/usr/bin/clamscan;
LOG_FILE=/home/user/clamscan.log;
SCAN_FOLDER=/;
# Start the log entry
$ECHO Complete system virus scan starting >> $LOG_FILE;
$DATE >> $LOG_FILE;
$ECHO \* >> $LOG_FILE;
# Update Virus definitions
$FRESHCLAM >> $LOG_FILE;
# Run the scan
$CLAMSCAN -ri $SCAN_FOLDER >> $LOG_FILE;
# Finish the log entry
$ECHO \* >> $LOG_FILE;
$ECHO Complete system virus scan finished >> $LOG_FILE;
$DATE >> $LOG_FILE;
$ECHO \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* >> $LOG_FILE;
$cat clamscan.log | mail -s "ClamAV Scan" someone@server.com
$rm clamscan.log
設定限權
sudo chown root /usr/local/bin/virus_scan.sh
sudo chmod u=rwx /usr/local/bin/virus_scan.sh
sudo chmod go= /usr/local/bin/virus_scan.sh
把shell加到 crontab 內
sudo vim /etc/crontab
20 3 * * * root /usr/local/bin/virus_scan.sh
# 記得更改 LOG_FILE , SCAN_FOLDER
# 想用gmail寄可參考 ubuntu 10.04 上,透過 gmail 用命令列寄信
shell 修改自http://ubuntuforums.org/showthread.php?t=631293
ubuntu 10.04 上,透過 gmail 用命令列寄信
$ vim ~/.mailrc
set from="YOURNAME@gmail.com (YOURNAME)"
set sendmail="/usr/bin/msmtp"
set message-sendmail-extra-arguments="-a gmail"
$ vim ~/.msmtprc
defaults
logfile /home/USER/msmtp.log
# gmail account
account gmail
auth on
host smtp.gmail.com
port 587
user YOURNAME@gmail.com
password YOURPASSWORD
from YOURNAME@gmail.com
tls on
tls_trust_file /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt
# set default account to use (not necessary with single account)
account default : gmail
$ chmod 600 ~/.msmtprc
$ echo "Hello, world!" | mail -s "Test from command line" -a attachment.txt somebody@somedomain.org
ssmtp也有相同作用, 但ssmtp會把帳密以明碼存在/etc/下,會增有gmail被帳號被盜。
參考
How To Use Gmail Account To Relay Email From a Shell Prompt
在 Ubuntu 8.04 上透過 gmail 用命令列寄信
2010年5月7日星期五
雨
狂風首先響起左前奏, 雨聲令我既注意力再度分散, 走左出去露台觀雨。雨似雨, 又不似雨。初聽之下,雨聲就是雨聲, 突然雨聲變了沙鎚聲,然後一下閃電, 又一下,就好像要說明佢係特別既。 不知何時,雨聲又變回雨聲。
回想最初對雨既印象,就係細個阿媽買左一套黃色既雨衣同雨BOOT, 但係等左好耐都無落雨。過左好似三年咁耐, 終於可以穿甲上陣。雖然同樣都係返學日,但係係雨水陪伴之下就變得有趣得多。雨聲就好似無數既朋友不斷同你傾計,你只要細心傾聽,就可以聽到佢地既言語。冰涼既雨水隔住雨衣都可以感受到,令夏日既刺熱感完全消退。青蛙既叫聲取代左吵耳既蟬聲,好似氣定神閒咁唱緊歌。雨聲又掩蓋左人們煩燥既談話聲,感覺就好似去左熱帶雨林,平時既不自覺既壓力消去得無影無終。我, 愛雨。
回到現實,蛙叫聲已經聽唔到, 換黎既黎低沈既船鳴聲, 可能它在悲叫吧? 在這七百萬人的都市中,也許只有我聽到, 但我又能做什麼? 破!! 突然雷聲一響,喝止了雨, 也喝止了夢。

又,雨停了又落, 就好似女人既心情咁, 永遠都睇唔通。
2009年7月25日星期六
Benchmarking php op-codes caches
1)No PHP op-code cache:
Document Path: /cookingbama/food.php?food_id=3
Document Length: 5489 bytes
Concurrency Level: 5
Time taken for tests: 50.571265 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Total transferred: 17199000 bytes
HTML transferred: 16467000 bytes
Requests per second: 59.32 [#/sec] (mean)
Time per request: 84.285 [ms] (mean)
Time per request: 16.857 [ms] (mean, across all concurrent requests)
Transfer rate: 332.11 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 30 83 47.7 73 322
Waiting: 30 81 47.3 70 322
Total: 30 83 47.7 73 322
Percentage of the requests served within a certain time (ms)
50% 73
66% 96
75% 109
80% 120
90% 149
95% 177
98% 214
99% 236
100% 322 (longest request)
2)Xcache:
Document Path: /cookingbama/food.php?food_id=3
Document Length: 5489 bytesConcurrency Level: 5
Time taken for tests: 4.970640 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Total transferred: 17199000 bytes
HTML transferred: 16467000 bytes
Requests per second: 603.54 [#/sec] (mean)
Time per request: 8.284 [ms] (mean)
Time per request: 1.657 [ms] (mean, across all concurrent requests)
Transfer rate: 3378.84 [Kbytes/sec] receivedConnection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 2 7 4.1 7 48
Waiting: 2 7 4.1 7 47
Total: 2 7 4.1 7 48Percentage of the requests served within a certain time (ms)
50% 7
66% 9
75% 10
80% 10
90% 12
95% 15
98% 18
99% 21
100% 48 (longest request)
3)eAccelerator
Document Path: /cookingbama/food.php?food_id=3
Document Length: 5489 bytesConcurrency Level: 5
Time taken for tests: 6.9865 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Total transferred: 17199000 bytes
HTML transferred: 16467000 bytes
Requests per second: 499.18 [#/sec] (mean)
Time per request: 10.016 [ms] (mean)
Time per request: 2.003 [ms] (mean, across all concurrent requests)
Transfer rate: 2794.57 [Kbytes/sec] receivedConnection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 9
Processing: 3 9 6.1 8 57
Waiting: 3 9 6.1 8 57
Total: 3 9 6.1 8 57Percentage of the requests served within a certain time (ms)
50% 8
66% 10
75% 12
80% 13
90% 18
95% 22
98% 26
99% 30
100% 57 (longest request)
Xcache is the winner.
2009年7月16日星期四
mysql INSERT OR UPDATE
平時我都會先select count(1) 看看有沒有已存表格, 再分別insert 或 update, 今天才發現原來可以一句ko:
ON DUPLICATE KEY UPDATE
CREATE TABLE ipstat(ip int UNSIGNED NOT NULL PRIMARY KEY, hits int UNSIGNED NOT NULL, last_hit timestamp);
INSERT INTO ipstat VALUES(inet_aton('192.168.0.1'),1,now()) ON duplicate KEY UPDATE hits=hits+1;
2009年4月15日星期三
Kill Processes Quickly With PKILL
To kill a process I've always either used top, or the kill or killall commands along with ps|aux to discover process numbers/names. However, the pkill command removes a lot of work -- pkill firefox, for example, will search the list of processes for anything matching firefox, and then kill it (i.e. send a SIGTERM). pstree is also a pretty cool command, and will show all the processes in a family-tree arrangement, organized by who owns them."
From:
10 Expert Ubuntu Tricks - Business Center - PC World
2009年1月18日星期日
把firefox 設為ubuntu 的 default browser
./firefox.exe -silent -setDefaultBrowser
firefox.exe 是program file 下的 , 而非安裝檔。
2009年1月17日星期六
my conky config
# Conky sample configuration
#
# the list of variables has been removed from this file in favour
# of keeping the documentation more maintainable.
# Check http://conky.sf.net for an up-to-date-list.
# set to yes if you want Conky to be forked in the background
background yes
# X font when Xft is disabled, you can pick one with program xfontsel
#font 5x7
#font 6x10
#font 7x13
#font 8x13
#font 9x15
#font *mintsmild.se*
#font -*-*-*-*-*-*-34-*-*-*-*-*-*-*
# Use Xft?
use_xft yes
# Xft font when Xft is enabled
xftfont Bitstream Vera Sans Mono:size=8
# Text alpha when using Xft
xftalpha 0.8
# Print everything to stdout?
# out_to_console no
# MPD host/port
# mpd_host localhost
# mpd_port 6600
# mpd_password tinker_bell
# Print everything to console?
# out_to_console no
# mail spool
mail_spool $MAIL
# Update interval in seconds
update_interval 5.0
# This is the number of times Conky will update before quitting.
# Set to zero to run forever.
total_run_times 0
# Create own window instead of using desktop (required in nautilus)
own_window no
# If own_window is yes, you may use type normal, desktop or override
own_window_type desktop
# Use pseudo transparency with own_window?
own_window_transparent yes
# If own_window_transparent is set to no, you can set the background colour here
own_window_colour black
# If own_window is yes, these window manager hints may be used
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes
# Minimum size of text area
minimum_size 280 5
# Draw shades?
draw_shades yes
# Draw outlines?
draw_outline no
# Draw borders around text
draw_borders no
# Draw borders around graphs
draw_graph_borders no
# Stippled borders?
stippled_borders 8
# border margins
border_margin 4
# border width
border_width 1
# Default colors and also border colors
default_color white
default_shade_color black
default_outline_color black
# Text alignment, other possible values are commented
#alignment top_left
#alignment top_right
alignment middle_right
#alignment bottom_right
#alignment none
# Gap between borders of screen and text
# same thing as passing -x at command line
gap_x 12
gap_y 12
# Subtract file system buffers from used memory?
no_buffers yes
# set to yes if you want all text to be in uppercase
uppercase no
# number of cpu samples to average
# set to 1 to disable averaging
cpu_avg_samples 2
# number of net samples to average
# set to 1 to disable averaging
net_avg_samples 2
# Force UTF8? note that UTF8 support required XFT
override_utf8_locale yes
# Add spaces to keep things from moving about? This only affects certain objects.
use_spacer none
# Allow each port monitor to track at most this many connections (if 0 or not set, default is 256)
#max_port_monitor_connections 256
# Maximum number of special things, e.g. fonts, offsets, aligns, etc.
#max_specials 512
# Maximum size of buffer for user text, i.e. below TEXT line.
#max_user_text 16384
# Timing interval for music player thread, e.g. mpd, audacious
#music_player_interval (update_interval is default)
# variable is given either in format $variable or in ${variable}. Latter
# allows characters right after the variable and must be used in network
# stuff because of an argument
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
# stuff after 'TEXT' will be formatted on screen
TEXT
${font Bitstream:size=14}${color1}${time %Y-%m-%d %A}
${font Radio Space:size=55}${color1}${time %H:%M}
${voffset -15}${font ConkyWeather:size=36}c ${font Verdana:size=15}${voffset -5}${execi 3600 conkyForecast --location=CHXX0049 --datatype=LT} / ${execi 3600 conkyForecast --location=CHXX0049 --datatype=HT}
$stippled_hr
${font Verana:style=Bold:size=9}HDD Temperature: ${font Verana:size=8}${execi 3 ~/.conky/gethddtemp.sh}
${font Verana:style=Bold:size=9}GPU Temperature: ${font Verana:size=8}${execi 3 nvclock -T | grep "temperature" | grep "[0-9][0-9]" -o}°C
${font Verana:style=Bold:size=9}CPU Temperature: ${font Verana:size=8}${acpitemp}°C
${font Verana:style=Bold:size=9}CPU1: ${font Verana:size=8}${cpu cpu1}% ${cpubar cpu1}
${font Verana:style=Bold:size=9}CPU2: ${font Verana:size=8}${cpu cpu2}% ${cpubar cpu2}
${font Verana:style=Bold:size=9}RAM Usage:${font Verana:size=8}$color $mem/$memmax - $memperc% ${membar}
${font Verana:style=Bold:size=9}Swap Usage:${font Verana:size=8}$color $swap/$swapmax - $swapperc% ${swapbar}
$stippled_hr
${font Verdana:style=Bold:size=9}Name PID CPU% MEM
${font}${color #ddaa00} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
${font}${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
${font}${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
${font}${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}
${font Verdana:style=Bold:size=9}Mem usage
${font}${color #ddaa00} ${top_mem name 1} ${top_mem pid 1} ${top_mem cpu 1} ${top_mem mem 1}
${font}${color lightgrey} ${top_mem name 2} ${top_mem pid 2} ${top_mem cpu 2} ${top_mem mem 2}
${font}${color lightgrey} ${top_mem name 3} ${top_mem pid 3} ${top_mem cpu 3} ${top_mem mem 3}
${font}${color lightgrey} ${top_mem name 4} ${top_mem pid 4} ${top_mem cpu 4} ${top_mem mem 4}
$stippled_hr
${font Verana:style=Bold:size=9}IP Address: ${font Verana:size=8}${addr eth0}
${font Verana:style=Bold:size=9}Total Download: ${font Verana:size=8}${totaldown eth0}
${font Verana:style=Bold:size=9}Total Upload: ${font Verana:size=8}${totalup eth0}
${font Verana:style=Bold:size=9}Up Speed: ${font Verdana:size=8}${upspeed eth0} Kb/s ${font Verana:style=Bold:size=9}Down Speed: ${font Verdana:size=8}${downspeed eth0} Kb/s
$stippled_hr
${font Verana:style=Bold:size=9}BOINC:
${font Verana:style=Bold:size=9}${execi 10 perl ~/.conky/boinc.pl}
$stippled_hr
${font Verana:style=Bold:size=9}$nodename - $kernel on $machine
2009年1月13日星期二
用AUTOIT 打造自動安裝軟件
- 執行安裝檔
- 等候
- 輸入
- 等候
- .
- .
- .
- 完成
執行:
Run("./install.exe")
等候:
WinWaitActive("title","inline")
輸入:
Send("!N")
-! 即 with alt
修正UBUNTU 下 NFS 關機不會UMOUNT的問題
umountnfs.sh 會自動umount所有的nfs。所以建立umountnfs.sh的連結檔,放在 /etc/rc0.d 興 /etc/rc6.d/下就可以了。
sudo ln -s /etc/init.d/umountnfs.sh /etc/rc0.d/K15umountnfs.sh
sudo ln -s /etc/init.d/umountnfs.sh /etc/rc6.d/K15umountnfs.sh
2009年1月12日星期一
套用YSlow!提供的建議 , 改進Apache 的效能
1) 打開需要的Apache_mod
首先要打開 authn_default , expires 兩個Apache_mod。 在Webmin下可輕易開啟。
要檢查相關的mod 是否正確開啟, 可以用PHP 的 phpinfo();
2) 修改httpd.conf
能改善的分別有三個, 分別為:
- 取消eTag
- 增加 Expires 的Header
- 啟用Gzip
在httpd.conf下, 加上
FileETag None
ExpiresActive On
ExpiresByType text/css "access plus 60 month"
ExpiresByType text/javascript "access plus 60 month"
ExpiresByType application/x-javascript "access plus 60 month"
ExpiresByType image/gif "access plus 60 month"
ExpiresByType image/jpg "access plus 60 month"
ExpiresByType image/png "access plus 60 month"
ExpiresByType image/x-icon "access plus 1 month"
SetOutputFilter DEFLATE
2009年1月2日星期五
mootools 解決 a 不可以有 target 的問題
解決的方法是用javascript把全部含 rel="external"的a都用js的方法開新tab.
方法如下:
var ExternalLink=function(){
$$('a[rel="external"]').each(function(a){
a.addEvent('click',function(e){
var e = new Event(e);
e.stop();
window.open(a.getProperty('href'));
});
});
}
2008年12月29日星期一
把UBUNTU WUBI 轉移到 正式的 EXT3 partition
第一步 : 分割一個新的文件系統
我將會使用 UBUNTU 的Live CD來分割 一個新的文件系統。當然你也可以用其他工具分割。
- 使用Live CD開機
- 按系統, Partition Editor
- 選目前的文件系統, 按 "Resize"
- 按 "Apply"
- 在"未使用空間"內, 創造兩個新的文件系統。 其一為 SWAP, 大小約2000MB; 其二為 EXT3, 使用全部剩餘空間
- 按 "Apply"
第二步 : 安裝與使用LVPM
- 進入Wubi 的 UBUNTU
- 到這下載最新的LVPM, 並進行安裝
- 在LVPM的對話框內, 選"TRANSFER" , "sda3"(按你的硬碟位置而定, 可到"硬碟分割處理器"查看 )
- 重新開機
- 在GRUB內, 選新的UBUNTU。 如果顯示"Error 17: Cannot mount selected partition." 則繼續下一步; 沒有的話, 你已經成功了 ^^
- 按"e"修改指令。把 "root ()" 改為 "root (hd0,2) " hd0指第一隻硬碟, 2指第3個文件系統, 請按自已的環境更改。
- 進入新的ext3 ubuntu 後, 請到"
/boot/grub/menu.lst" 把 新的"root ()" 改為 "root (hd0,2) " - 完成了^^
原文参考: http://www.saltycrane.com/blog/2008/08/notes-moving-ubuntu-wubi-standard-ext3-partition-using-lvpm/
2008年12月22日星期一
PHP 繁簡字碼直接轉換
- detect charset
- 簡繁轉換
總結如下:
iconv斷字
icon 遇到無法轉換的字時, 預設是會斷句。
可以在第2個参數加入//IGNORE
iconv("BIG5","UTF-8//IGNORE",$query);
或//TRANSLIT
iconv("BIG5","UTF-8//TRANSLIT",$query);
//TRANSLIT will raise an exception on characters it can't transliterate, however; this can be solved by using '//IGNORE//TRANSLIT' together (in that order).
iconv("BIG5","UTF-8//IGNORE//TRANSLIT",$query);
用mb_convert_encoding 的話, 但會把有問題的字換成 "?"
gb->utf8
iconv("GBK","UTF-8//ignore",$word);
iconv("GB2312","UTF-8//ignore",$word);
用GBK比GB2312好, 據說係因為GBK既字庫比較大
mb_convert_encoding
mb_convert_encoding($word,"UTF-8","BIG-5");
有以下地方要注意:
- 参數次序跟ICONV剛好倒轉
- "BIG5" 要換成 "BIG-5"
- "EUC-CN"要換成"GB2312"
- "CP936" 要換成 "GBK"
charset detecting
$encoding_list="UTF-8,BIG-5,EUC-CN";mb_detect_encoding($word, $encoding_list);
$encoding_list為 charset 的次序
-繁簡字碼可能會誤測, 所以次序很重要
繁簡換轉
上GOOGLE搜尋一下,
如果想簡轉繁的話, 方法是 UTF-8 -> GB2312 -> BIG5 -> UTF-8, 的確是可行的, 也不用任何外部的文件。但因為BIG5和 GB2312的字庫不夠UTF-8的大, 所以總有些字會變成 "?"。
解決方法是找個 簡體的UTF-8 -> 繁體UTF-8 的MAP , 再跟據MAP直接轉換。問GOOGLE後發現好像沒有人試過這樣做, 所以就寫了個類轉換。
源碼可以這下載
http://code.google.com/p/fukidutf8t2s/
2008年12月15日星期一
2008年12月11日星期四
09年計劃
- 幫樂a level
- 改裝個 mini laptop
- 整html2rss既interface
- 整online mp3 player with lyric support
第2樣要做既就係買返部mini laptop。 性能對我黎講無乜所謂, 上到網就得, 最重要既反而係續航力。一開始睇中aspire one, 性能ok, 但係續航力得3小時, 坐兩程車就用哂d電啦, 唔夠耐。 再搵左陣見到 eeepc 901,6cell電可以開成6個鍾機, 性能都唔差, 而且白色都ok型仔, 真係岩哂我心水。
我既plan係買完部laptop之後, 就cut左個keyboard同加個touch screen
跟住就係個html2rss啦。 個程式本來係諗住 for d 無rss既 網頁既, 不過整下整下好似變左偷全文既工咁, ha, 我就係咁奸架啦。其實html2rss個底(腦?)已經整好左, 係差個display未整, 不過都已經有個idea, 希望可以用得上之前學左既gimp黎整d圖啦 。
最後就係個online mp3 player。我既idea其實就係網頁既千千靜聽。家下好似唔多見有網提供歌詞識換句既網wor, 同埋我點都覺得有個server side係度,想換client果陣都易d , 第時部laptop整好左之後就唔洗煩要點將d歌同步啦
ha, 4個target入面 , 無一樣野係關學業事架wor
-------------------------------------------
11/12
提醒一下, 動態歌詞可以在百度下載
