2010年6月10日

Drupal 架站筆記-雙語言網站

用 Views 來做一個顯示「最新消息」的區塊
http://riemann.math.nccu.edu.tw/forum/viewtopic.php?f=8&t=637
Views 的選項:
  • Basic Information:  View 的名稱
  • 頁面: 要做一個 page 時要用這一個。
  • 區塊: 區塊的設定。因為我們要做的是「最新消息」的區塊, 所以選用這一項。
  • Fields: 選擇要把 Node 的什麼部份顯示出來, 例如標題 (Title)。
  • Arguments: ...。
  • 過濾器: 沒有要把所有的 Nodes 顯示出來時, 要設一些條件。
  • Exposed Filters
  • Sort Criteria
相簿 show:  Dynamic display block模組
http://chenyuyi.mis.nchu.edu.tw/drupal-6.16/node/59

待確認:
區塊 (block) 的雙語模型 要用哪一個模組?

待試用的 modules


Better Formats
不同 role 指定不同輸入格式 (是否允許 HTML)
http://drupal.org/project/better_formats



Nice Menus
下拉 css 選單
http://drupal.org/project/nice_menus

2010年5月10日

ASP 中的 codepage

放在 *.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 中使用:
例 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
在終端機下指令, 讓此檔變成可執行
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"
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
---end of the script---

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 &

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
重新啟動後, 休眠功能回復了, 但喚醒後, 滑鼠不動 (還沒解決) 

2010年2月26日

ubuntu 自動登入後, 無線網路每次都必需輸入 keyring 密碼的不方便問題

不想每次自動登入 ubuntu 後, 還要輸入鑰匙圈的密碼 (keyring),可參考此網站的做法 (但可能不是很安全喔)

http://maketecheasier.com/auto-unlock-keyring-manager-in-ubuntu-intrepid/2009/03/14
應用程式->附屬應用程式->密碼及加密金鑰
然後在出現的視窗主選單中, 選 ->編輯->偏好設定, 按 [更改解鎖密碼] 鈕, 輸入原有密碼後, 不輸入新密碼 (就是留空白), 重新開機後, 應該就不用再輸入密碼了! Yeah!