the lost utf8 encoding

0

更新紀錄

  1. 2006-1001 還是發生亂碼現象,這次進去看才發現原來之前的設定 /usr/bin/env ruby 並不一定會抓 /home/foo/bin/ruby 而是根據 fcgi 的設定,往往是 /usr/bin/ruby-1.8。之前如減少 500 建議又加上 frao_handler 試圖 reload 被 DH 定時砍的 fcgi ,也許在 reload 時出現問題 ? 刪除後觀察看看。

源起

之前一直遭遇亂碼問題 typo 4 post install ,終於到了需要攤牌的時候,經過一陣子觀察,發現混用環境會用到同帳號下面其他虛擬主機的 MySQL 連線,而剛好這個 foo 虛擬主機只是測試用,並沒有正常設定資料庫需要的 encoding 連結參數,這下子就慘了。

$ ps aux | grep xxx
xxx 20120  0.2  0.6 29140 26564 ?       S    19:07   0:02 ruby dispatch.fcgi
xxx 26233  0.4  0.9 46028 36960 ?       S    19:08   0:04 ruby dispatch.fcgi
xxx 11270  0.2  0.6 29140 26568 ?       S    19:11   0:02 ruby dispatch.fcgi
xxx 14002  0.0  0.0  6488 1880 ?        S    19:19   0:00 sshd: linthink@pts/6
xxx  6930  0.0  0.0  4788 1684 pts/6    Ss   19:19   0:00 -bash
xxx 13610  0.8  0.6 29140 26556 ?       S    19:20   0:02 ruby dispatch.fcgi
xxx  9397  0.7  0.5 24684 22136 ?       S    19:22   0:01 /usr/bin/ruby1.8 dispatch.fcgi
xxx  4355  0.0  0.0  2484  860 pts/6    R+   19:24   0:00 ps aux
xxx 24377  0.0  0.0  4788 1688 pts/6    R+   19:24   0:00 -bash

一發生亂碼現象,馬上連進去看看現場,發現 ruby1.8 這個行程應該不存在,這是系統提供的 ruby ,但是我的 blog 站 typo 確是用私有 ruby,這代表有人在使用 foo 虛擬主機下的服務。

$ ls -al /proc/9397/
-r--r--r--    1 xxx sasl 0 2006-09-21 19:25 cpu
lrwxrwxrwx    1 xxx sasl 0 2006-09-21 19:25 cwd -> /kkk/foo.extremepattern.com/public
-r--------    1 xxx sasl 0 2006-09-21 19:25 environ
lrwxrwxrwx    1 xxx sasl 0 2006-09-21 19:25 exe -> /usr/bin/ruby1.8

進去 proc 看看,果然是虛擬主機 foo,先試著關掉 dispatch.fcgi 看看。

$ cd foo.extremepattern.com/public
$ mv .htaccess htaccess.bak

kill 這個不速之客後,reload 部落格網頁,還是喚起這個屬於 foo 的連線,猜測應該是某種連接池關係,所以還是一堆亂碼。只好把其他 ruby 行程全砍,然後再進 typo 管理將快取清過,總算恢復編碼正常。

一小時代價

看了一下,發現之前不注意,有一篇文章被上面的程序,導致亂碼污了資料庫,先到 phpmyadmin 查到這筆紀錄 更改時間是 2006-09-05 18:35:21,再去找備份 sql 截取出這段紀錄,重新貼上。同時這代表後來逐日備份全部 遭到污染。

結論

  1. 同一個帳號環境要一樣
  2. 備份很重要,舊的不要刪掉
  3. 小問題還是要先解決,亂碼污染資料庫到幾百筆就難清了
  4. rails 共用環境是新的需求,遠不如 PHP 等共用環境穩定。

rail crash

0

源起

之前網路應用都在 java web 環境上發展,開始學 ror 會有點不習慣,需要做點轉換,覺得有不習慣的地方,在這裡紀錄一下。

error page

typo 的做法是 route.rb 下面加一行做 route globbing 全攬下來,但這只能擋住 RoutingError, 要擋 UnknownAction 的做法是靠 ActionController::Rescue 救援。

上產品模式後會轉 404/500 頁面,並不會出現 RoutingError/UnknownAction,這點又需要注意。

http://www.typosphere.org/trac/browser/trunk/config/routes.rb http://www.typosphere.org/trac/browser/trunk/app/controllers/articles_controller.rb http://dev.rubyonrails.org/svn/rails/trunk/railties/configs/routes.rb

Rails 分開發跟產品模式的錯誤處理往往讓人一頭霧水,個人覺得蠻複雜的,上線後都還需要 再測一次才知道,特別是貪圖方便去改 environments/production.rb 或是 development.rb 後, 就是後面惡夢的開始。

dot NET Compact Framework

0

源起

想要一個可以運作 12-18 小時的聯網裝置,需求如下。

  1. 低於 NT 5000
  2. 可以寫程式開發應用
  3. 可以使用 skype
  4. 用 wifi 聯網
  5. 低耗電
  6. VGA 輸出 640×480
  7. 觸控輸入
  8. 免費的程式開發環境
  9. SD 存放
  10. USB host

看起來拍賣的 Acer n300 規格過一年後會比較接近。

developer tool

SharpDevelop

SD Targeting Different Frameworks

dot net cf

Resources about .NET Compact Framework

How to Create Multithreaded Application Using the .NET Compact Framework 2.0

Tips & Tricks & Best Practices with Multithreading and .NET CF

NET CF and Google APIs

C# Remote Control using the Audio Port

links

Pocket Sudoku

small linux device

0

源起

需要低成本的改裝 linux 裝置,用來當家中的常駐程式。

linux

nslu2-linux

nslu2 上面可以接的東西

Adding Zigbee Radio to a Slug

WhatPeopleAreReallyUsingTheirSlugsFor

Linux on the NSLU2

linkstation and kuro-box

LinkStationWiki

免拆機、不破壞保固之 LinkStation 軟體改機

Matrix Orbital Displays and Linux

Linux LCD display driver

matrixorbital

links

Embedded Java with GCJ

單晶片微電腦

凱思嵌入式系統開發網

eclipse and OSGi

0

源起

想開發基於 RCP 之上的應用,就需要了解其底層使用的 OSGi 運作機制。OSGi 基本上希望軟體可以像現在 USB 一樣熱插拔,既然 USB 需要 OS 支援,應用程式就需要 OSGi 來做這個事,讓符合規格的應用程式可以直接熱插拔,甚至可以挑版本插拔,聽起來好像不錯。

What’s New

  1. 2006-09-23 新增螢幕展示 screencast

Open Services Gateway in Eclipse

大部分的 Java 開發者都直接用 IDE,並不太會去動到 eclipse 的內部,eclispe IDE 本身由一堆 plug-ins 組成,同時提供一個 OSGi 的環境供 plug-ins 運作,提供整個開發所需的功能。

慢慢地有人覺得 minimum eclipse plug-ins 可以方便再利用來開發 eclipse IDE 類似桌面型軟體,所以 Eclipse Rich Client Platform (RCP) 慢慢成形,RCP 牽涉到 plug-ins 取捨,選哪些 eclipse plug-ins 可以方便以後大家使用,當然 OSGi 也要一起包起來帶走。

RCP 包起來的環境中都可以找到這個實作 rcp/plugins/org.eclipse.osgi_3.x.x.jar。

osgi console

先進入 console 狀態

C:\Downloads\EclipseInstall\OSGi>java -Dosgi.install.area=file://c:/downloads/ 
-cp org.eclipse.osgi_3.2.0.v20060601.jar
org.eclipse.osgi.framework.launcher.Launcher -console

launch 後到 http://www.knopflerfish.org/repo/index.html 找一些下載。

osgi> ss

Framework is shutdown.

id      State       Bundle
0       RESOLVED    system.bundle_3.2.0.v20060601

osgi> launch

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601

osgi> install http://www.knopflerfish.org/repo/jars/log/log_all-2.0.0.jar
Bundle id is 1

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0

osgi> start 1

啟動失敗,會告知缺少 org.osgi.service.cm,換一個不相依commons-logging_all-2.0.0.jar 試過,可以啟動。

osgi> install http://www.knopflerfish.org/repo/jars/commons-logging/commons-logging_all-2.0.0.jar
Bundle id is 2

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0
2       INSTALLED   org.knopflerfish.bundle.commons-logging_2.0.0

osgi> start 2

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0

加上 cm 看看。

osgi> install http://www.knopflerfish.org/repo/jars/cm/cm_all-2.0.0.jar
Bundle id is 4

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0
4       INSTALLED   org.knopflerfish.bundle.cm_2.0.0

osgi> start 4

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       RESOLVED    org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0
4       ACTIVE      org.knopflerfish.bundle.cm_2.0.0

osgi> start 1

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       ACTIVE      org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0
4       ACTIVE      org.knopflerfish.bundle.cm_2.0.0

screencast 螢幕展示

覺得手動太麻煩 ? 可以用 eclipse 來玩,非常簡單,幾分鐘就可以。

screencast

  1. 用 3.2 版
  2. 只有選 plug-in 專案,沒有 Bundle 專案,以後也許會改比較 OSGi 的說法。
  3. 用 Equinox 當底層
  4. 都幫你出好了,雖然應該用 Bundle 比較適合
  5. 直接用範本,連程式碼都不用打
  6. 直接就可以跑
  7. 檢視一下
  8. 匯出 jar
  9. 順便匯出 ant 的 build.xml 參考
  10. 看一下成果
  11. 建立一個純的 osgi 環境,只取 org.eclipse.osgi 一個 jar
  12. 直接吃剛才編出的 jar 看看。

產出的 ant build.xml 可是好東西,對於需要 自動化產出 Bundle 的人來說,用起來會很方便。

small osgi 螢幕展示

關於 eclipse 開發的螢幕展示還可以參考下面連結,將 OSGi 環境建立在改造過小型 NAS 裝置上面,在遠端用 eclipse 開發。

Coding bundles on the Slug demo movie

Remote debugging on the Slug demo movie

OSGi 移植到小裝置上的做法,也許 gcj 也是一種可以考慮的做法。

OpenSlug Gateway Installation – OSGi on the NSLU2

OSGi on the Slug

將 OSGi 真的變成 Open Services Gateway 似乎需要一點時間,目前 IBM 在這個領域推蠻久的。

Managed mobile clients with OSGi: Managed smart clients

IBM Workplace Client Technology, Micro Edition and Open Services Gateway Initiative

links 參考

Developing Eclipse/OSGi Web Applications

OSGi Everywhere

Spring and OSGi, A Perfect Match?

Spring and OSGi

Understanding how Eclipse plug-ins work with OSGi

Launching Eclipse OSGi Framework from the command line

OSGi Open Source Market

Knopflerfish – Open Source OSGi

Java: 淺談 OSGi 標準

Older posts: 1 2 3 ... 5