安裝 xsane
sudo aptitude install xsane
並加入 scanner group
sudo usermod -G scanner -a muchu1983
之後在X的功能選單下就可以使用XSane進行掃描。
2009年2月23日 星期一
2009年2月16日 星期一
使用 springframework 3.0.0 建立 RESTful 網路應用程式 Controller
RESTful是一種新的Webapp設計概念,可以減少很多傳統Webapp程式的code,
傳統Webapp以一個 url mapping 到一個 service ,如 java servlet 或 spring controller,
以操作資料庫的 CRUD 四個步驟來說,一張資料表至少就需要4個 service 命令來完成實作。
也就是要分別對四個 url 進行操作。
RESTful 則將資料當成一種資源,利用 http 原本就有的 Get、Post、Delete、Put…
等七個 method ,對同一個 url 進行操作,如下圖。

spring 在 3.0版之後的 spring MVC 框架就有提供 RESTful 相關的支援,並使用 java 5.0 的
annotation 語法,用起非常簡單方便。
spring 3.0.0 相依的 jar有:
antlr-3.0.1.jar
asm-3.1.jar
asm-common-3.1.jar
commons-logging.jar
log4j-1.2.13.jar
簡單的 RESTful 範例 /rest/{i}/{n} : i、n 均為變數
web.xml 加入 DispatcherServlet 的servlet定義,並mapping到 /rest/*
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/conf/spring-restful-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
需注意:
DispatcherServlet 因為被 mapping 到 /rest/* 所以在 DispatcherServlet 帶起來的WebApplicationContext 之下 做mapping時, "/"符號就等於 "/rest/"這一層 ,
也就是說 html form action 的 "/rest/1/2/3/4" mapping 要寫成 "/1/2/3/4"。
在 web.xml 指定了 /WEB-INF/conf/spring-restful-config.xml 這個檔為 spring bean config
內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!-- test jsp view -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="testController"
class="com.transtep.restful.server.framework.spring.controller.TestController">
</bean>
</beans>
spring-restful-config.xml 檔裡有 2 個 bean 負責 spring 2.5 開始有的 annotation MVC功能,
DefaultAnnotationHandlerMapping -> 處理 class level 的 annotation。
AnnotationMethodHandlerAdapter -> 處理 method level 的 annotation。
底下再定義 Controller 的 bean class,這些 bean 就可以用 annotation 的語法來定義了。
如這裡的 TestController :
@Controller
public class TestController {
@RequestMapping(value = "/1/{ii}/{nn}", method = RequestMethod.GET)
public ModelAndView getTest(@PathVariable(value = "ii") String id, @PathVariable(value = "nn") String number) {
System.out.println("run 1");
Map model = new HashMap();
model.put("message", "id " + id + "\n" + "number " + number);
return new ModelAndView("test", model);
}
@RequestMapping(value = "/1/{ii}/{nn}", method = RequestMethod.POST)
public ModelAndView postTest(@PathVariable(value = "ii") String id, @PathVariable(value = "nn") String number) {
Map model = new HashMap();
model.put("message", "id " + id + "\n" + "number " + number);
return new ModelAndView("test", model);
}
}
首先在 class 宣告上以 @Controller 定義這是一個 Controller (不需要再implements Controller)
再以 @RequestMapping 定義各別的 method 的 URI 、 method mapping,特別是 URI 可以{}
定義成變數的格式,再配合 @PathVariable 將變數的實際值綁到 method的參數上,同時根據
方法的參數型別不同,自動轉換成正確的型別。
上面的例子以 get /rest/1/123/456 則會執行 getTest() 方法,id=123,number=456
而如果以 post /rest/1/456/789 則會執行 postTest() 方法,id=456,number=789
傳統Webapp以一個 url mapping 到一個 service ,如 java servlet 或 spring controller,
以操作資料庫的 CRUD 四個步驟來說,一張資料表至少就需要4個 service 命令來完成實作。
也就是要分別對四個 url 進行操作。
RESTful 則將資料當成一種資源,利用 http 原本就有的 Get、Post、Delete、Put…
等七個 method ,對同一個 url 進行操作,如下圖。

spring 在 3.0版之後的 spring MVC 框架就有提供 RESTful 相關的支援,並使用 java 5.0 的
annotation 語法,用起非常簡單方便。
spring 3.0.0 相依的 jar有:
antlr-3.0.1.jar
asm-3.1.jar
asm-common-3.1.jar
commons-logging.jar
log4j-1.2.13.jar
簡單的 RESTful 範例 /rest/{i}/{n} : i、n 均為變數
web.xml 加入 DispatcherServlet 的servlet定義,並mapping到 /rest/*
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/conf/spring-restful-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
需注意:
DispatcherServlet 因為被 mapping 到 /rest/* 所以在 DispatcherServlet 帶起來的WebApplicationContext 之下 做mapping時, "/"符號就等於 "/rest/"這一層 ,
也就是說 html form action 的 "/rest/1/2/3/4" mapping 要寫成 "/1/2/3/4"。
在 web.xml 指定了 /WEB-INF/conf/spring-restful-config.xml 這個檔為 spring bean config
內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!-- test jsp view -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="testController"
class="com.transtep.restful.server.framework.spring.controller.TestController">
</bean>
</beans>
spring-restful-config.xml 檔裡有 2 個 bean 負責 spring 2.5 開始有的 annotation MVC功能,
DefaultAnnotationHandlerMapping -> 處理 class level 的 annotation。
AnnotationMethodHandlerAdapter -> 處理 method level 的 annotation。
底下再定義 Controller 的 bean class,這些 bean 就可以用 annotation 的語法來定義了。
如這裡的 TestController :
@Controller
public class TestController {
@RequestMapping(value = "/1/{ii}/{nn}", method = RequestMethod.GET)
public ModelAndView getTest(@PathVariable(value = "ii") String id, @PathVariable(value = "nn") String number) {
System.out.println("run 1");
Map
model.put("message", "id " + id + "\n" + "number " + number);
return new ModelAndView("test", model);
}
@RequestMapping(value = "/1/{ii}/{nn}", method = RequestMethod.POST)
public ModelAndView postTest(@PathVariable(value = "ii") String id, @PathVariable(value = "nn") String number) {
Map
model.put("message", "id " + id + "\n" + "number " + number);
return new ModelAndView("test", model);
}
}
首先在 class 宣告上以 @Controller 定義這是一個 Controller (不需要再implements Controller)
再以
定義成變數的格式,再配合 @PathVariable 將變數的實際值綁到 method的參數上,同時根據
方法的參數型別不同,自動轉換成正確的型別。
上面的例子以 get /rest/1/123/456 則會執行 getTest() 方法,id=123,number=456
而如果以 post /rest/1/456/789 則會執行 postTest() 方法,id=456,number=789
2009年2月10日 星期二
在 xorg.conf 檔調整顯示器的水平垂直更新率
每個場商的每個螢幕的設定範圍都不同,即使設定不正確螢幕也不一定就沒畫面,
有可能是在執行某些需要特殊畫面更新率的軟體,例如640x480解析度的遊戲時,
會因為更新率不支援(其實是沒設定好),而造成畫面一片黑,出現 out of range 等等。
先查詢螢幕的正確水平,垂直更新率。
編輯 /etc/X11/xorg.conf
找到 Section "Monitor" 裡面有 HorizSync VertRefresh 兩項,
各自填入查到的 水平(HorizSync)、垂直(VertRefresh) 更新率,
有時可能填的範圍要比查詢到的還小一點,50.0 - 80.0 可以只填 30.0 - 70.0就好。
更新後 startx 進入X,切換一下解析度,看看能不能正常顯示。
有可能是在執行某些需要特殊畫面更新率的軟體,例如640x480解析度的遊戲時,
會因為更新率不支援(其實是沒設定好),而造成畫面一片黑,出現 out of range 等等。
先查詢螢幕的正確水平,垂直更新率。
編輯 /etc/X11/xorg.conf
找到 Section "Monitor" 裡面有 HorizSync VertRefresh 兩項,
各自填入查到的 水平(HorizSync)、垂直(VertRefresh) 更新率,
有時可能填的範圍要比查詢到的還小一點,50.0 - 80.0 可以只填 30.0 - 70.0就好。
更新後 startx 進入X,切換一下解析度,看看能不能正常顯示。
2009年2月8日 星期日
lenny中使用wine設定執行魔獸爭霸3
首先安裝wine就不多說了,我使用的是1.0.1-1
安裝好wine後,先執行winecfg設定一下
1.windows版本的地方選windows 2000
2.函式庫->已有的函式庫頂替 維持空的
3.顯示 -> 模擬一個虛擬桌面 打勾 800x600
4.儲存槽 -> 按一下自動偵測 讓wine對應linux的路徑到磁碟機代號
開始安裝Warcraft3,如果已經有安裝好的則直接copy過來linux下,跳過這一步
mount主程式的光碟,並在光碟的掛載點下執行wine install.exe
mount資料片的光碟,並在光碟的掛載點下執行wine install.exe
更新patch
下載 http://todian.myweb.hinet.net/ 提供的傻瓜包來更新
更新完成後也會變成免光碟版,一樣以 wine 執行更新程式,
wine warcraft_patch_upgrade_122a_v3.exe
選擇Warcraft III的安裝(或copy)資料夾,由於傻包完成後會自動執行遊戲,
但wine的Directx3D還不夠完整,現在執行畫面可能一片黑,先想辦法關掉遊戲
大絕招是ctrl-alt-←關掉整個X再startx
透過安裝步驟 wine的register表也會自動加入Warcraft資料,
但如果是從別的地方copy的,就要手動去新增wine register裡的資料
執行 regedit
找到下列的key,如果沒有就按右鍵新增key(一個key就是一層資料夾)
HKEY_CURRENT_USER\Software\Blizzard Entertainment\Warcraft III
在右側建立名為Gfx OpenGL的DWORD值,Value data設置為1
(這個regedit主要設定War3以opengl執行遊戲)
現在回到 Warcraft III 資料夾下,執行
wine War3.exe -opengl或wine War3.exe -x11
順利的話會在wine虛擬桌面下看到開場動畫,等動畫播完,遊戲畫面會一片黑
滑鼠點一下黑色的遊戲畫面,則遊戲界面就會出來。先離開遊戲
再次執行 winecfg
將 顯示 -> 模擬一個虛擬桌面 打勾取消掉
重新回到Warcraft III 資料夾下,執行
wine War3.exe -opengl或wine War3.exe -x11
就可以以全螢幕進行遊戲了。
(因為開場動畫沒有用虛擬桌面的話就不能播)
安裝好wine後,先執行winecfg設定一下
1.windows版本的地方選windows 2000
2.函式庫->已有的函式庫頂替 維持空的
3.顯示 -> 模擬一個虛擬桌面 打勾 800x600
4.儲存槽 -> 按一下自動偵測 讓wine對應linux的路徑到磁碟機代號
開始安裝Warcraft3,如果已經有安裝好的則直接copy過來linux下,跳過這一步
mount主程式的光碟,並在光碟的掛載點下執行wine install.exe
mount資料片的光碟,並在光碟的掛載點下執行wine install.exe
更新patch
下載 http://todian.myweb.hinet.net/ 提供的傻瓜包來更新
更新完成後也會變成免光碟版,一樣以 wine 執行更新程式,
wine warcraft_patch_upgrade_122a_v3.exe
選擇Warcraft III的安裝(或copy)資料夾,由於傻包完成後會自動執行遊戲,
但wine的Directx3D還不夠完整,現在執行畫面可能一片黑,先想辦法關掉遊戲
大絕招是ctrl-alt-←關掉整個X再startx
透過安裝步驟 wine的register表也會自動加入Warcraft資料,
但如果是從別的地方copy的,就要手動去新增wine register裡的資料
執行 regedit
找到下列的key,如果沒有就按右鍵新增key(一個key就是一層資料夾)
HKEY_CURRENT_USER\Software\Blizzard Entertainment\Warcraft III
在右側建立名為Gfx OpenGL的DWORD值,Value data設置為1
(這個regedit主要設定War3以opengl執行遊戲)
現在回到 Warcraft III 資料夾下,執行
wine War3.exe -opengl或wine War3.exe -x11
順利的話會在wine虛擬桌面下看到開場動畫,等動畫播完,遊戲畫面會一片黑
滑鼠點一下黑色的遊戲畫面,則遊戲界面就會出來。先離開遊戲
再次執行 winecfg
將 顯示 -> 模擬一個虛擬桌面 打勾取消掉
重新回到Warcraft III 資料夾下,執行
wine War3.exe -opengl或wine War3.exe -x11
就可以以全螢幕進行遊戲了。
(因為開場動畫沒有用虛擬桌面的話就不能播)
2009年2月7日 星期六
debian下apache2安裝mod_python模組
首先安裝好apache2
sudo aptitude install apache2
安裝好後預設的web context根目錄會在/var/www下
安裝mod_python模組
sudo aptitude install libapache2-mod-python
設定網站支援mod_python
vim /etc/apache2/sites-available/default
在Directory /var/www的項目中
把內容改為:
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
存檔
重新啟動apache
/etc/init.d/apache2 restart
這樣就完成mod_python的安裝與設定了
現在可以建立python程式
vi /var/www/test.py
內容為:
#!/usr/bin/env python
def index(req):
return "Test successful";
以browser連到 http://localhost/test.py
就可以看到 Test successful 的輸出結果。
sudo aptitude install apache2
安裝好後預設的web context根目錄會在/var/www下
安裝mod_python模組
sudo aptitude install libapache2-mod-python
設定網站支援mod_python
vim /etc/apache2/sites-available/default
在Directory /var/www的項目中
把內容改為:
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
存檔
重新啟動apache
/etc/init.d/apache2 restart
這樣就完成mod_python的安裝與設定了
現在可以建立python程式
vi /var/www/test.py
內容為:
#!/usr/bin/env python
def index(req):
return "Test successful";
以browser連到 http://localhost/test.py
就可以看到 Test successful 的輸出結果。