[工具] 碩、博士論文致謝詞產生器

Written on 11:47 下午 by Yu Lai

http://tfanalysis.zooserver.net/jotting/acknowledge.php

哎呀,好物啊~當初在寫論文時怎麼沒有這種東西可以用啊?

[技術] FreeBSD/Linux的Booting from network

Written on 3:08 下午 by Yu Lai

最近要搞在Mips的板子上搞Embedded Linux,
要透過網路開機來啟動,所以有了幾下的研究。

其概念為client開機時透過網卡的設定呼叫dhcp或bootp取得ip,
並向server以tftp的方式將boot image檔載入執行開機的動作。

在FreeBSD/Linux上可以透過網路開機,
設定的方法依照機器的網路卡功能的支援不同而有所不一樣。
以下是常見的幾種方式和設定方法:
(PS: 以下設定以Linux為主,FreeBSD則會有些許的不同。)

1. rboot
先介紹rboot
1.1 取得rbootd
如果你的網卡支援rboot開機的話,你必須有台Server來負
責handle boot request,所以首先你必須安裝rbootd。

1.2 設定rbootd
安裝完rbootd後需設定rbootd.conf來設定rbootd。
一般而言rbootd會位於/etc/rbootd.conf
設定範例如下:

# ethernet addr        boot file           comments
08:00:09:87:e4:8f lifimage_715 # PA/Linux kernel for 715/33
08:00:09:70:04:b6 lifimage_720 # PA/Linux kernel for 720
1.3 安裝boot file
將在rbootd.conf裡設定的boot file置於rbootd的目錄,一般是/var/lib/rbootd。

2. dhcp/tftp
這是最常見的一種方式,也是目前主流的diskless system建置的方法。

2.1 取得dhcp/tftp
先透過rpm或apt-get等方式來安裝server必要的檔案。
rpm: dhcp tftpd
(FreeBSD可以用Ports安裝/usr/ports/net/isc-dhcp3-server即可)

2.2 設定dhcp/tftp
1.修改/etc/inetd.conf或/etc/xinetd.d/tftp
inetd.conf中加入:
tftp           dgram   udp     wait    nobody  /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot
xinetd.d/tftp:
service tftp
{
disable = no //yes改成no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -c -s /tftpboot //加上-c參數
per_source = 11
cps = 100 2
flags = IPv4
}
改完後接著重新啟動inetd或xined。
(FreeBSD則是改/etc/inetd.conf並在/etc/rc.conf中啟動inetd。)
這邊要注意的是我們必須將開機用的檔案放置於/tftpboot中。
2. 參考man 5 dhcpd.conf來修改dhcpd.conf,範例如下:
allow bootp;
default-lease-time 600;
max-lease-time 7200;
# This will tell the box its hostname while booting:
use-host-decl-names on;

subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option domain-name "foo.com";
option domain-name-server 192.168.1.4;
}
host tatooine {
hardware ethernet 00:40:05:18:0c:dd;
fixed-address 192.168.1.22;
filename "lifimage-tatooine";
option root-path "/exports/tatooineroot";
}
3. bootp/tftp
這是和dhcp/tftp類似,主要是dhcp已經將bootp的功能包含在一起的關係。
但由於網路架構的關係(e.g. 已有dhcp server),也是個常見的採用方式。

3.1 取得bootp/tftp
先透過rpm或apt-get等方式來安裝server必要的檔案。
rpm: bootp tftpd
(FreeBSD皆已內建其中)

3.2 設定bootp/tftp
1.修改/etc/inetd.conf或/etc/xinetd.d/tftp
inetd.conf中加入:
tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot
bootps dgram udp wait root /usr/sbin/bootpd bootpd -i -t 120
xinetd.d/tftp和xinetd.d/bootps:
service tftp
{
disable = no //yes改成no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -c -s /tftpboot //加上-c參數
per_source = 11
cps = 100 2
flags = IPv4
}
service bootps
{
disable = no //yes改成no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/bootpd
server_args = -i -t 120
per_source = 11
cps = 100 2
flags = IPv4
}
改完後接著重新啟動inetd或xined。
(FreeBSD則是改/etc/inetd.conf並在/etc/rc.conf中啟動inetd。)
這邊要注意的是我們必須將開機用的檔案放置於/tftpboot中。
2. 參考man 5 bootptab來修改/etc/bootptab,範例如下:
vodka:hd=/tftpboot:\
:rp=/usr/src/parisc/:\
:ht=ethernet:\
:ha=080069088717:\
:ip=140.244.9.208:\
:bf=lifimage:\
:sm=255.255.255.0:\
:to=7200:

[技術] Tomcat的OutOfMemory issue

Written on 10:00 上午 by Yu Lai

最近在幫Pinter弄系統,發現Tomcat偶爾會噴OutOfMemory
的Exception出來,而在Console中也沒有辦法Trace出怎麼發生的。
Survey了一下才發現,原來除了存取大量的資料外,在Tomcat中使用
Singleton Pattern會有這類問題。

原因如下:
Hard references to classes can prevent the garbage collector from reclaiming the memory allocated for them when a ClassLoader is discarded. This will occur on JSP recompilations, and webapps reloads. If these operations are common in a webapp having these kinds of problems, it will be a matter of time, until the PermGen space gets full and an Out Of Memory is thrown.

而解決方法有三種:
Workaround 1: Move the class to another classloader
This workaround is for the case this class should be shared between webapps, or if the server will contain only one webapp. That is, we need to use the same instance across several webapps in the same server, or there is no need to worry about it. In this case, the class will need to be deployed on a shared classloader. This means this class must be in the shared/lib or shared/classes directory.

This way, the class will be loaded by a parent classloader, and not by the webapp classloader itself, so no resources need to be reclaimed on webapp reloadings.

This workaround may not always fit well with your code or design. In particular, care must be taken to avoid the singleton to keep references to classes loaded through the webapp classloader, because such references would prevent the classloader from being deallocated. A servlet context listener could be used to get rid of those references before the context is destroyed.

Workaround 2: Use commons-discovery
If you need to have a singleton instance for each webapp, you could use commons-discovery. This library provides a class named DiscoverSingleton that can be used to implement singletons in your webapp.

For using it, the class to be used as singleton will need to implement an interface (SPI) with the methods to be used. The following code is an example of usage of this library:

MyClass instance = DiscoverSingleton.find(MyClass.class, MyClassImpl.class.getName());
It is important, for this library to work correctly, to not keep static references to the returned instances.

Just by using this syntax, you get the following advantages:

Any class could be used as a singleton, as long as it implements an SPI interface.

Your singleton class has been converted into a replaceable component in your webapp, so you can "plug-in" a different implementation whenever you want.

But only this does not make for a workaround. The most important advantage is the DiscoverSingleton.release() method, that releases all references to instantiated singletons in the current classloader. A call to this method could be placed into a ServletContextListener, into its contextDestroyed() method.

That is, with a ServletContextListener simple implementation like the following:

public class SingletonReleaser implements ServletContextListener {
public contextInitialized(ServletContextEvent event) { }

public contextDestroyed(ServletContextEvent event) {
DiscoverSingleton.release();
}
}
we could release all cached references to the instantiated singletons. Of course, this listener should be registered on the web.xml descriptor before any other listener that could use a singleton.

Workaround 3: Use ServletContext attributes
This refactoring will work well provided the ServletContext instance is available, as a local variable or as a parameter.

It will be more efficient than using commons-discovery, but has the disadvantage of making your code depend on the web layer (ServletContext class). Anyway, I have found out that, in some cases, it is a reasonable approach.

There are many ways to do this refactoring, so I will just present one implementation that works well for me:

Create the following ServletContextListener:

public class SingletonFactory implements ServletContextListener {
public static final String MY_CLASS = "...";

/**
* @see ServletContextListener#contextInitialized(ServletContextEvent)
*/
public void contextInitialized(ServletContextEvent event) {
ServletContext ctx = event.getServletContext();
ctx.setAttribute(MY_CLASS, new MyClass());
}

/**
* @see ServletContextListener#contextDestroyed(ServletContextEvent)
*/
public void contextDestroyed(ServletContextEvent event) {
ctx.setAttribute(MY_CLASS, null);
}

/**
* Optional method for getting the MyClass singleton instance.
*/
public static MyClass getMyClassInstance(ServletContext ctx) {
return (MyClass)ctx.getAttribute(MY_CLASS);
}
}
Register the listener in the web.xml descriptor

Replace the calls to MyClass.getInstance() by:

MyClass instance = (MyClass)ctx.getAttribute(SingletonFactory.MY_CLASS);

/* or, if implemented:
MyClass instance = SingletonFactory.getMyClassInstance(ctx);
*/

[閒聊] 玻璃渣跟南方公園合作的影片

Written on 10:44 下午 by Yu Lai

http://www.youtube.com/watch?v=IFN_ceKOcbU&mode=related&search=
一共三集...真是太好笑了...lololol
看著南方公園的畫面..背景是阿拉希戰場的音樂...好惡搞啊...XD
還惡搞B社的員工跟老闆..自己開發的..卻都沒有遊戲角色帳號....
搶車那一段..應該是惡搞GTA系列吧...還蠻像的...cc
不過最後那一把神兵怎麼沒有靈魂綁定啊...=.=

[閒聊] 偽基百科

Written on 2:02 下午 by Yu Lai

http://zh.uncyclopedia.info/

PS: 個人覺得內容還蠻腦殘的啦..

[閒聊] 英文的數字單位

Written on 11:29 上午 by Yu Lai

今天剛好有聊到,想說就做個筆記吧。


yotta = 1024
zetta = 1021 十垓
exa = 1018 百京
peta = 1015 千兆
tera = 1012
giga = 109 十億
mega = 106 百萬
kilo = 103

mini = 10-3
micro= 10-6
nano = 10-9

PS: 毫微奈的記憶法可以用"好無奈"來幫助記憶..XD

[技術] 解決samba的charset問題

Written on 11:28 上午 by Yu Lai

就在9/11那天所po的"[技術] 在FreeBSD上掛載smbfs"中,其實有個問題沒有被提到,而是最近才解決的,那就是charset的問題。

在那台Linux上是採用zh_TW.Big5的編碼,其檔案系統也是採用Big5來儲存檔名。而在FreeBSD那台是採用zh_TW.UTF-8,自然的透過mount_smbfs來掛載會出現亂碼的問題,在經過測試,發現mount_smbfs -E的選項可說是無效..XD

所幸,解決的方法是根據samba的The Official Samba-3 HOWTO and Reference Guide中的
Chapter 30. Unicode/Charsets裡提到的:
As of Samba-3, Samba can (and will) talk Unicode over the wire. Internally, Samba knows of three kinds of character sets:

unix charset
This is the charset used internally by your operating system. The default is UTF-8, which is fine for most systems and covers all characters in all languages. The default in previous Samba releases was to save filenames in the encoding of the clients for example, CP850 for Western European countries.

display charset
This is the charset Samba uses to print messages on your screen. It should generally be the same as the unix charset.

dos charset
This is the charset Samba uses when communicating with DOS and Windows 9x/Me clients. It will talk Unicode to all newer clients. The default depends on the charsets you have installed on your system. Run testparm -v | grep "dos charset" to see what the default is on your system.

也就是只要將unix charset和display charset皆設為配合系統設定的Big5的CP950,然後在dos charset設為UTF-8,這樣透過mount_smbfs來掛載時就會自動轉成UTF-8的編碼了。而目前的成果自然就是FreeBSD上的pure-ftp (with utf-8 support)可以多很多東西囉。

[技術] BT備用Tracker列表

Written on 7:27 下午 by Yu Lai

雖然不一定有用,但勉強加入看看吧。

http://tracker.so-ga.net/announce
udp://tracker.bitcomet.net:8080/announce
udp://bt.lanspirit.net:2710/announce
http://btfans.3322.org:6969/announce
http://btfans.3322.org:8080/announce
http://tracker.prq.to/announce.php
http://tracker.prq.to:80/announce.php
http://tracker.prq.to/announce
http://tracker.prq.to:80/announce
http://bt.cnxp.com:8080/announce
http://bt.cnxp.com:6969/announce
http://privatetracker.limitedivx.com:2710/announce.php
http://tracker.torrentz.info:42426/announce
http://tracker.torrentportal.com:6969/announce
http://tracker1.desitorrents.com:6969/announce

[技術] 在FreeBSD上掛載smbfs

Written on 12:36 上午 by Yu Lai

最近,在弄lab的ftp整合計畫。
要將另一台Linux的資料透過samba的方式來掛載到ftp那台FreeBSD上。
以下則是在弄的過程所得到的一些Notes。

首先,我們可以透過以下的指令來察看有提供連線的資料
smbutil view

掛載時則使用
mount_smbfs //[username]@[host]/[service] [mountpoint]

若要加入 /etc/fstab 使開機後自動mount,請先編輯 /etc/nsmb.conf
加入[host:user]的 section,注意! host及section都必須為"大寫",既使平常輸入的是小寫!
然後在該section加入
password=[encrypted_password] (由smbutil crypt算出)

最後,在 /etc/fstab 裡加上:
//[username]@[host]/[service] [mountpoint] smbfs rw,-I=xxx.xxx.xxx.xxx,-N,-u=[uid],-g=[gid] 0 0

要測試是否成功可以用:
mount -a
來觀看結果。

[技術] 解決Blogger下IE顯示問題

Written on 5:40 下午 by Yu Lai

IE在判斷charset時,會先判斷html檔內的文字編碼,
再去判斷Web Server所提供的charset資訊。
一般而言,這樣是不會有什麼大問題。
但問題就出在判斷html檔內的<meta>資訊前,如果先遇到
<title>時會自動去判斷charset而不理會<meta>所設定的charset。

也就是說如果在Blogger下使用UTF-8編碼,IE會因為這樣的Bug而導致畫面一片空白。
遇到這樣的問題,解決的方法進到Blogger裡的範本修改一下囉。
將<head>裡的
<title><$BlogPageTitle$></title>
<$BlogMetaData$>
順序改一下,將<title>往後調,讓IE先讀取<meta>的資訊即可解決。

[技術] 在Linux上掛載FreeBSD的UFS

Written on 6:19 下午 by Yu Lai

Linux從Kernel 2.6.x開始對FreeBSD的UFS有著良好的支援,
對於FreeBSD的Slice也可以對應良好,但在mount時有些參數
仍需注意一下。

以下是在Linux上要mount UFS的一些注意的地方:
首先先用dmesg找到UFS所在的device node,
e.g.
hdc: ST380021A, ATA DISK drivehdc: max request size: 128KiB
hdc: 156312576 sectors (80032 MB) w/2048KiB Cache, CHS=65535/16/63, UDMA(33)
hdc: hdc1
hdc1: <bsd: hdc5 hdc6 hdc7 hdc8 hdc9 >
然後再執行mount指令來掛載ufs,因為要掛載slice,所以要在options中加入ufstype=ufs2。
# mount -t ufs -o ufstype=ufs2,ro /dev/hdc9 /mnt

[紀念] 偶畢業啦

Written on 11:08 下午 by Yu Lai

就是今天,就是今天。
今天拿到畢業證書,辛苦兩年終算有結果了。
恭喜自己一下 ^____^

[技術] 寫AppleScript叫Mail自動轉寄信件

Written on 12:58 上午 by Yu Lai

相信大家都有用到Forward的功能吧,
而一些好文章也都會轉來轉去的吧。
但如果是一堆mail就會按forward再打
mail address等同樣的動作弄到煩吧.. XD

身為懶人的我,找了一下網路,寫了這樣功能的AppleScript。

tell application "Mail"
set theMessages to the selection
repeat with thisMessage in theMessages
set newMessage to make new outgoing message at end of outgoing messages
tell newMessage
set content to thisMessage's content
set subject to thisMessage's subject
make new to recipient with properties {address:"blahblah@blahblah.org"}
end tell
send newMessage
delete thisMessage
end repeat
end tell

[閒聊] HiNet ADSL連接無名小站加速法

Written on 3:10 上午 by Yu Lai

http://stilnox.myweb.hinet.net/h2w.htm
以上是教學網頁。

懶得點進去看的話就看這裡吧。
簡單的說,就是設Proxy啦。
無名小站有提供Proxy的pac檔,URL在
http://proxy.wretch.cc/proxy.pac
不過我還是建議點進去看一下啦,他結論寫的還不錯。

引用一下: (~~謎之音~~)
賓士車與國產車都是車啊!一樣都可以從台北開到高雄啊!沒有理由要買貴的啊!

[技術] JavaScript Debug Utility

Written on 9:45 下午 by Yu Lai

http://www.isocra.com/articles/jsdebug.php
這是Script方式來達到debug的功能。
因為平時如果Script沒寫好連alert都跳不出來,
這個剛好避過這個問題。

如果偏好使用IDE的話,也有好用的Tool。
http://www.aptana.com/
Aptana的特點是可以以stand-alone方式執行,
也可以以plug-in方式執行於Eclipse。

[技術] PHP的檔案上傳

Written on 3:36 下午 by Yu Lai

PHP在裝好後預設的檔案上傳只能傳2MB,實在有點不夠用。
所以要修改一下php.ini來達到需求。
以下幾個是要修改的變數:

  • file_uploads
  • upload_max_filesize
  • max_input_time
  • memory_limit
  • max_execution_time
  • post_max_size

以下將分別對各變數詳細說明

upload_max_filesize and post_max_size

一般而言,檔案是採用POST method以'multipart/form-data'的格式從Browser上傳至Web Server。所以除了要加大upload_max_filesize外還需加大post_max_size。這邊要注意的是upload_max_filesize是設定上傳的檔案大小,而post_max_size的大小除了檔案的大小外還需加上其他的field和header data。

memory_limit

因為php engine在處理POST時會將data存於memory中,所以這個變數也需加大才行。

max_execution_time and max_input_time

最後要注意的是這2個timeout的設定,因為傳大檔時所需時間會較久,請參考網路環境來設定這2個值較好。

註:有些Web Server會設定限制Request大小的設定,如Apache的LimitRequestBody,遇到這種情況時也需一併修改加大。

[閒聊] 台灣大百科

Written on 1:04 上午 by Yu Lai

台灣大百科是台灣自己的維基百科!

眾所周知維基百科(Wikipedia)是集合網友之力,一起編撰,卻很少人知道,台灣自己
也有一本「維基百科」--「台灣大百科全書」,目前已累積8,500篇內容。
台灣大百科全書網站(http://taipedia.cca.gov.tw)是由政府單位架設的第一個全民參
與台灣知識建構的網站,由文建會全權負責,成立初衷是希望藉助現代網路科技的便捷與
快速傳播功能,凝聚全國民眾的力量,於最短時間完成以台灣觀點為主的百科全書,提供
認識、研究台灣最好的管道。

[閒聊] BSD統計使用量計畫

Written on 1:17 上午 by Yu Lai

bsdstats一個新的專案, 用來統計BSD的使用量外加硬體設備.目的是告訴硬體廠商說:

"你看有那麼多人用你們的產品上面跑的是*BSD, 不要認為這是小眾市場!"

加入統計的方法很簡單

  1. 更新port tree
  2. cd /usr/ports/sysutils/bsdstats ; make install clean
  3. 遵照安裝完後的指示作就可以啦

有網頁有真相: http://bsdstats.org/
手邊有BSD的長輩們快幫台灣衝台數阿阿阿!!!

[閒聊] 第一篇

Written on 12:36 上午 by Yu Lai

剛好最近在弄實驗室的blog, 自己也剛好開始來玩一玩吧.
算是給自己多一個發表一些雜七雜八的地方囉..XD