放在 *.asp 的第1行:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
936代表是簡體中文,而950代表繁體中文,65001就是 UTF-8 編碼了
若你的 *.asp 是 UTF-8 編碼, 則加入以下的程式碼在第1行, 就不會有亂碼了
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
2010年4月23日
Regular Expression 語法
在很多程式中見到看起來很怪的語法, 中文稱為「正規表達式 」,例如
([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})代表 yyyy-mm-dd 的日期格式, 或
a[0-9]*\.c
代表 a12.c,a932.c 等以 a 開頭, 以 .c 結尾, 中間只能是數字, 的所有字串
還滿聰明的一個做法
參見
特別要抓 unicode 中文的話, 看這裡
它使用「/xxx/u」,在最後加上「u」,以這方式支援 UTF-8,
#!/usr/bin/php -q
$a = "def:123:這是:AB=你好!";
$pattern =
'/123:([\x{4e00}-\x{9fff}]+):[A-B]*/u';
preg_match($pattern,
$a,$match);
echo $match[0];
?> ASP 中使用:
- asp 的RegExp對象正則表達式功能用法
- VBScript Regular Expressions (英文, 有範例)
- 用 {var} 或 {var1+var2} 語法來取代變數的範例: 可應用於樣版 (見例 2)
例 1
Function RegExpTest(patrn, strng) Dim regEx, retVal ' 建立變量。 Set regEx = New RegExp ' 建立正則表達式。 regEx.Pattern = patrn ' 設置模式。 regEx.IgnoreCase = False ' 設置是否區分大小寫。 retVal = regEx.Test(strng) ' 執行搜索測試。 If retVal Then RegExpTest = "找到一個或多個匹配。" Else RegExpTest = "未找到匹配。" End If End Function
例 2
s1="This equation {x} + {y} = {x+y}
"
x=100
y=200
response.write "====>" & Var2Value(s1) & "
" function Var2Value(var_name) Var2Value = Txt2Value(var_name, 1) end Function
function Txt2Value(str, level)
dim regEx, Matches, Result
Set regEx = new RegExp
select case level
case 0 regEx.Pattern = "\{([\w\(\)]+)\}" '變數名有效判斷
case 1 regEx.Pattern = "\{([\w+\-\*/\\<>=\(\)]+)\}" '變數名及運算符號有效
'case 2 regEx.Pattern = "\{([\w\s\(\)]+)\}" '除換行符外的所有字符有效
case else exit function
end select
regEx.IgnoreCase = true
regEx.Global = true
Set Matches = regEx.Execute(str)
Result = str
'response.write Matches.Count
For Each Match In Matches
Result = Replace(Result, Match.Value, GetVar(Match.SubMatches(0)))
Next
set Matches = nothing
set regEx = nothing
Txt2Value = Result
end function
2010年3月1日
ubuntu 9.10 (Karmic) 下 firefox 的64 bit flashplugin 安裝
以下程式碼是從 http://the3mingheats.blogspot.com/2009/12/64bit-flash-player-on-linux.html?zx=a7531bec64ff2e02 抓來修改的
將以下程式碼複製後, 存成文字檔, 例如 install.sh
在終端機下指令, 讓此檔變成可執行
Youtube 中文字有亂碼則參見這一篇: Ubuntu 8.10 AMD64 安裝了flash播放器,中文是亂碼
64 bit flash player for Firefox 可從此處下載: http://labs.adobe.com/downloads/flashplayer10_64bit.html
---beginning of the script---
將以下程式碼複製後, 存成文字檔, 例如 install.sh
在終端機下指令, 讓此檔變成可執行
chmod +x install.sh然後執行
./install.sh
Youtube 中文字有亂碼則參見這一篇: Ubuntu 8.10 AMD64 安裝了flash播放器,中文是亂碼
64 bit flash player for Firefox 可從此處下載: http://labs.adobe.com/downloads/flashplayer10_64bit.html
---beginning of the script---
echo "Stopping any Firefox that might be running"---end of the script---
sudo killall -9 firefox
echo "Removing any other flash plugin previously installed:"
sudo apt-get remove -y --purge flashplugin-nonfree gnash gnash-common mozilla-plugin-gnash swfdec-mozilla libflashsupport nspluginwrapper
sudo rm -f /usr/lib/mozilla/plugins/*flash*
sudo rm -f ~/.mozilla/plugins/*flash*
sudo rm -f /usr/lib/firefox/plugins/*flash*
sudo rm -f /usr/lib/firefox-addons/plugins/*flash*
sudo rm -rfd /usr/lib/nspluginwrapper
echo "Installing Flash Player 10"
cd ~
wget http://download.macromedia.com/pub/labs/flashplayer10/libflashplayer-10.0.45.2.linux-x86_64.so.tar.gz
tar zxvf libflashplayer-10.0.45.2.linux-x86_64.so.tar.gz
sudo cp libflashplayer.so /usr/lib/mozilla/plugins/
echo "Linking the libraries so Firefox and apps depending on XULRunner (vuze, liferea, rsswol) can find it."
sudo ln -sf /usr/lib/mozilla/plugins/libflashplayer.so /usr/lib/firefox-addons/plugins/
sudo ln -sf /usr/lib/mozilla/plugins/libflashplayer.so /usr/lib/xulrunner-addons/plugins/
# now doing some cleaning up:
sudo rm -rf libflashplayer.so
sudo rm -rf libflashplayer-10.0.45.2.linux-x86_64.so.tar.gz
2010年2月27日
在 ubuntu 下, 啟動第 2 個 X, 同時執行 linux 和 winXP
在 ubuntu 下, 啟動第 2 個 X, 同時執行 linux 和 winXP (in VirtualBox 全螢幕), 如此一來, 即像是在執行雙系統
1. 在 display:1 執行另一個 X, 再執行 xterm, (twm), VirtualBox
X -display :1 &
xterm -dsplay :1 &
VirtualBox -display :1 &
2. 按 [Ctrl+Alt+F9] 切換到 display:1 (按 [Ctrl+Alt+F7] 可切回 display:0)
在其中執行全視窗的 winXP in VirtualBox
若要執行全部 gnome 桌面的話, 下指令:
startx -- :1 -bpp 32 -quiet &
事實上, 只要執行以下指令即可
startx -- :1 &
1. 在 display:1 執行另一個 X, 再執行 xterm, (twm), VirtualBox
X -display :1 &
xterm -dsplay :1 &
VirtualBox -display :1 &
2. 按 [Ctrl+Alt+F9] 切換到 display:1 (按 [Ctrl+Alt+F7] 可切回 display:0)
在其中執行全視窗的 winXP in VirtualBox
若要執行全部 gnome 桌面的話, 下指令:
startx -- :1 -bpp 32 -quiet &
事實上, 只要執行以下指令即可
startx -- :1 &
ubuntu 9.10 無法休眠 (安裝時忘了建立 swap)
安裝 ubuntu 9.10 時, 忘記分割 swap, 所以無法休眠, 修正方法如下:
1. (可利用 gparted) 重新分割 swap
2. ls -l /dev/disk/by-uuid/ 找出 swap 分割區的 uuid, 以便掛載
或 sudo blkid
/dev/sda6: UUID="08c5f7ed-1cf2-4bc5-9cea-7534dd554e3c" TYPE="swap"
3. sudo gedit /etc/fsatb 修改自動掛載的分區檔, 紅字部份請填入剛剛得到的uuid
UUID=08c5f7ed-1cf2-4bc5-9cea-7534dd554e3c none swap sw 0 0
4. 修改 (或新增) sudo gedit /etc/initramfs-tools/conf.d/resume, 填入剛剛獲得的 UUID:
RESUME=UUID=08c5f7ed-1cf2-4bc5-9cea-7534dd554e3c
5. 重建initrt檔
sudo update-initramfs -u
重新啟動後, 休眠功能回復了, 但喚醒後, 滑鼠不動 (還沒解決)
1. (可利用 gparted) 重新分割 swap
2. ls -l /dev/disk/by-uuid/ 找出 swap 分割區的 uuid, 以便掛載
或 sudo blkid
/dev/sda6: UUID="08c5f7ed-1cf2-4bc5-9cea-7534dd554e3c" TYPE="swap"
3. sudo gedit /etc/fsatb 修改自動掛載的分區檔, 紅字部份請填入剛剛得到的uuid
UUID=08c5f7ed-1cf2-4bc5-9cea-7534dd554e3c none swap sw 0 0
4. 修改 (或新增) sudo gedit /etc/initramfs-tools/conf.d/resume, 填入剛剛獲得的 UUID:
RESUME=UUID=08c5f7ed-1cf2-4bc5-9cea-7534dd554e3c
5. 重建initrt檔
sudo update-initramfs -u
重新啟動後, 休眠功能回復了, 但喚醒後, 滑鼠不動 (還沒解決)
2010年2月26日
ubuntu 自動登入後, 無線網路每次都必需輸入 keyring 密碼的不方便問題
不想每次自動登入 ubuntu 後, 還要輸入鑰匙圈的密碼 (keyring),可參考此網站的做法 (但可能不是很安全喔)
http://maketecheasier.com/auto-unlock-keyring-manager-in-ubuntu-intrepid/2009/03/14
http://maketecheasier.com/auto-unlock-keyring-manager-in-ubuntu-intrepid/2009/03/14
應用程式->附屬應用程式->密碼及加密金鑰然後在出現的視窗主選單中, 選 ->編輯->偏好設定, 按 [更改解鎖密碼] 鈕, 輸入原有密碼後, 不輸入新密碼 (就是留空白), 重新開機後, 應該就不用再輸入密碼了! Yeah!
2010年2月20日
在 ubuntu 下架設 VPN
很久以前試了一次沒成功能, 再次找到這一個架設 VPN 的說明, 有空試試
see: http://gsyan888.blogspot.com/2009/11/ubuntu-vpn-server.html
所需套件:pptpd
設定檔案:/etc/pptpd.conf , /etc/ppp/pptpd-options , /etc/ppp/chap-secrets
1. 安裝 pptpd
指定當 client 連線成功以後分配 192.168.0.11 到 192.168.0.20 之間任一個 IP 給它,也可以用逗號分隔,一個個列表。
3. 修改 /etc/ppp/pptpd-options
這個檔案裡面,最重要的是兩項設定: name 和 ms-dns。
name 是定義在 /etc/ppp/chap-secrets 中第二個欄位(server name),因此兩邊要配合好,例如,下面是預設值:
此外,如果想幫 client 指定 WINS 則可以加入底下的設定:
4. 修改 /etc/ppp/chap-secrets
這個檔案主要是儲存 client 端進行 VPN 連線時的帳號、密碼資訊。例如:
5. 啟動 pptpd
如果前面的步驟都完成,就可以啟動 pptpd !執行:
see: http://gsyan888.blogspot.com/2009/11/ubuntu-vpn-server.html
所需套件:pptpd
設定檔案:/etc/pptpd.conf , /etc/ppp/pptpd-options , /etc/ppp/chap-secrets
1. 安裝 pptpd
apt-get update2. 修改 /etc/pptpd.conf
apt-get install pptpd
#server 端之 ip
localip 192.168.0.2
#要分配給 client 端之 ip
remoteip 192.168.0.11-20
指定當 client 連線成功以後分配 192.168.0.11 到 192.168.0.20 之間任一個 IP 給它,也可以用逗號分隔,一個個列表。
3. 修改 /etc/ppp/pptpd-options
這個檔案裡面,最重要的是兩項設定: name 和 ms-dns。
name 是定義在 /etc/ppp/chap-secrets 中第二個欄位(server name),因此兩邊要配合好,例如,下面是預設值:
name pptpd依前述設定,在 /etc/ppp/chap-secrets 中就必須是下面的格式
xxxx pptpd xxxx 1.2.3.4pptpd-options 中的另外一項要設的是 ms-dns ,它可以幫 client 端在連線成功以後指定 DNS,例如:
ms-dns 192.168.1.2client 端連線成功以後會指定 192.168.1.2 為 DNS。對 Windows 的 clinet 來說,這項設定最多可以有兩行,因為 Windows 只能指定最多兩個 DNS。
此外,如果想幫 client 指定 WINS 則可以加入底下的設定:
ms-wins 192.168.1.3上面的的設定可以幫 client 設定 WINS 到 192.168.1.3
4. 修改 /etc/ppp/chap-secrets
這個檔案主要是儲存 client 端進行 VPN 連線時的帳號、密碼資訊。例如:
username pptpd mypw *上面的設定:
- 帳號:username
- 主機:pptpd (參考 /etc/ppp/pptpd-options 中的 name)
- 密碼:mypw
5. 啟動 pptpd
如果前面的步驟都完成,就可以啟動 pptpd !執行:
/etc/init.d/pptpd start
或是
/etc/init.d/pptpd restart
訂閱:
文章 (Atom)