Tuesday, December 30, 2008


Saturday, December 13, 2008

simple clone of GitHub Badge

Thanks to jQuery, I just spend three hours to create GitHub Widget, a clone of GitHub Badge. The widget is put in the sidebar of this page.

Compare with GitHub Badge, GitHub Widget is full written in jQuery, so that it is also compatible with IE. And the usage and html structure is full compatible with GitHub Badge.

I host it here temporarily. Please feel free to use it.


github api callback

Not documented on Official GitHub API Guide, GitHub provide "callback" parameter to allow corss-site json accessing.

Example in jQuery:
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js' type="text/javascript"></script>


function myFunction(data) {
// data is the json we would get




hide blogger navigation bar


.Navbar {
display: none;


Friday, December 5, 2008

Thursday, November 6, 2008

perl work with growl

Excerpt from

A quick method to post notification to Growl.

#!/usr/bin/env perl

use warnings;
use strict;

use Mac::Growl qw(:all);

# register your application in Growl before posting.
# just one time enough.
'growlalert', # app name
['alert'], # all notification
['alert'], # default notification

# post notification to Growl
"growlalert", # app name
"alert", # notification type
"this is a title", # alert title
"this is a description", # alert content


Monday, October 13, 2008

push in scheme

01 (define push
02 (lambda (element stack)
03 (append stack (cons element '()))))
05 (push 'd '(a b c)) ; => (a b c d)

Though putting element before stack is a little weird XD.


Wednesday, September 17, 2008

tip in mpb

Defect mode always appears around the number of super lattice cells, so set num-bands automatically is a better way if we do not confirm how big the supper lattice.

(define-param supercell-x 5)
(define-param supercell-y 11)
(set! num-bands (+ 2 (* supercell-x supercell-y)))


Saturday, September 6, 2008


the default color scheme looks more beautiful in emacs.app. :D

From temp

Wednesday, September 3, 2008

expand tab

emacs: (setq-default indent-tabs-mode nil)
vim: set expandtab

but I could not find the setting in textmate :~


Sunday, August 31, 2008


01 class Array
02 def split(part)
03 num = self.length/part.to_i
04 result = Array.new
05 for row in 0..(part-1)
06 result[row] = self[num*row...num*(row+1)]
07 end
08 result
09 end
10 end

a = [1,2,3,4,5,6,7,8,9]
a.split(3).inspect # => [[1, 2, 3], [4, 5, 6], [7, 8, 9]]


Monday, August 11, 2008

build source package in debian

just for memo
need build-essential fakeroot

$ apt-get build-dep package
$ fakeroot apt-get source -b package

then wait for compilation.

$ dpkg -i package

so happy not messing with tarball


Sunday, August 10, 2008

safari history search

Using the shortcut Command-? for searching help to search history is a very good hacking.


Wednesday, August 6, 2008

ls_color in bsd style

for xterm-color, set in .profile

alias ls="ls -G"

make it more beautiful.


Sunday, August 3, 2008

set volume in max os x terminal

Costing my much time to search, It seems no command for setting volume in Leopard. When I used AppleScript to do this, I didn't know why the executable file cause some problem in screen. But Ruby's applescript gem do this good. I saved below content as /usr/bin/volume, and then I could use $ volume [1-7 as volume] to set Leopard's Volume from remote.

01 #!/usr/bin/env ruby
03 require 'rubygems'
04 require 'applescript'
06 AppleScript.execute("set volume #{ARGV[0]}")

update 2008/8/3

the way using applescript interpreter is $ osascript -e "set volume [1-7]"
or call in script by shebang.

01 #!/usr/bin/osascript
03 set volume [1-7]


Wednesday, July 30, 2008

basic gnuplot script

for plotting band data generated by mit photonics band

01 set title "band of te mode"
02 set term png
03 set output "te.png"
05 plot \
06 "te" using 2:7 title "band 1" with linespoints, \
07 "te" using 2:8 title "band 2" with linespoints, \
08 "te" using 2:9 title "band 3" with linespoints, \
09 "te" using 2:10 title "band 4" with linespoints, \
10 "te" using 2:11 title "band 5" with linespoints, \
11 "te" using 2:12 title "band 6" with linespoints, \
12 "te" using 2:13 title "band 7" with linespoints, \
13 "te" using 2:14 title "band 8" with linespoints


Tuesday, July 29, 2008

today's note

Simplicity is the ultimate sophistication.
-- Leonardo Da Vinci


Monday, July 28, 2008

ruby readline

loop do
line = Readline::readline("app shell> ")
if line
Readline::HISTORY.push line
puts line

This is a the most basic usage.
I want to find a way could act as irssi :/


Friday, July 18, 2008

多愁善感 淌 一點點

青春歲月 落 一片片








for A.L.


Monday, July 14, 2008







---謹致 A.L.(J)


Saturday, July 12, 2008

restful 與 form_for

不可以在 /news/new 的 view 裡面寫 form_for @news ~"~


Tuesday, June 3, 2008

operate existed tables in rails

Just need specify table name and primary key in Model. All attribution in tables will appear automatically.
class ModelName < ActiveRecord::Base
self.table_name = "table_name"
self.primary_key = "primary_key"


Saturday, May 24, 2008

tree implement in ruby

Just for fun, but it work well.

01 #!/usr/bin/env ruby
02 #
03 #
06 def tree(dirname, indent = " |")
07 puts dirname + "/" if indent == " |"
08 dir = Dir.open dirname
09 for f in dir
10 if f == "." || f == ".."
11 next
12 elsif File.directory? dirname+"/"+f
13 puts indent + "-" + f + "/"
14 tree( dirname+"/"+f, indent+" |")
15 else
16 puts indent + "-" + f
17 end
18 end
19 end
21 tree (ARGV[0]? ARGV[0] : ".")


Friday, May 23, 2008

closure tip

closure is so fun.
well design for meta programming.

note 1:

01 #!/usr/bin/env ruby
03 class Hash
04 def find_all
05 temp_hash = {}
06 each {|key,value| temp_hash[key] = value if yield(key,value) }
07 temp_hash
08 end
09 end
11 square = { 0 => 0, 1 => 1, 2 => 4, 3 => 9 }
13 new = square.find_all { |key,value| key > 1 }
14 puts new.inspect

pass yield values.

note 2:

01 #!/usr/bin/env ruby
03 class Person
04 attr_accessor :name
05 def initialize(name)
06 @name = name
07 end
08 end
10 def command(obj,method)
11 obj.each {|x| yield x.send(method)}
12 end
14 family = []
16 %w(shelling sherry appollo).each do |name|
17 family.push Person.new(name)
18 end
20 command family, :name do |x|
21 puts "hello, I am #{x}."
22 end

Every object in array call the same function.


Tuesday, May 20, 2008

Mac OS X Terminal tip

leopard terminal use xterm-color as default, but conflict with linux when ssh. The backspace act as delete(kill word at right not left). Mac OS hint provide a good solution, Copy /usr/share/terminfo/78/xterm-color on mac to ~/.terminfo/x/ on linux box. Not affect linux default setting. It saves my emacs in screen environment :D


Saturday, May 17, 2008

sample scheme

hello, world! here
#!/usr/bin/guile -s
(write "hello, world!")

define function
(define square (lambda (n) (* n n) ) )
(write (square 3) ) ; output 9

link1: The Scheme Programming Language 3/e
link2: Scheme Tutorial

Tuesday, May 13, 2008


買了 shelling.idv.tw,不過什麼都還沒配置 :D

Monday, May 12, 2008


some convenient usage I prefer. :p
package PackageName;
use self;
use strict;

my @args;

sub new {
@args = args;
for (@args) {
bless {}, self;



some vim

something is fun from learning the vi editor 6/e:
    dwelp change two words
xp change two alphabets

Sunday, May 4, 2008



Saturday, April 26, 2008

learning perl review ch2

    1.233, 2E-3, 3e45
# exponential float
# integer with underscore
0377, 0xff, 0b1111
# octal => 0, hexadecimal => 0x, binary => 0b
# concatenate with .
"hello" x 3
# repeat 3 time with x
"20fred" * 3
# ignore string when transform
$str = $str . "blah"; === $str .= "blah";
$int = $int ** 3; === $int **= 3;
# binary assignment operator
# insert variable with dereference brace
eq == | ne != | < lt | > gt | <= le | >= ge
# string comparison operator

# return with \n at line end
# return true or false

initial parameters (perl -M)
    use warnings;
use diagnostics;


Friday, April 25, 2008

boring comparison

show complex data structure in perl and ruby

#!/usr/bin/env perl
use warnings;
use Data::Dumper;

$a = ["a", "b", "c", { "key" => "value" } ];
print Dumper $a;

#!/usr/bin/env ruby
a = ["a", "b", "c", { "key" => "value" } ]
puts a.inspect

Saturday, April 19, 2008

has_many() function note

if has_many :order
order.delete_all just set foreign key null
order.destroy_all clear all sub record

Friday, April 18, 2008

apache2 and mongrel cluster on debian

Enable apache2 proxy
$ sudo a2enmod proxy proxy_http proxy_balancer

Configure Proxy in a virtual host
/etc/apache2/site-enabled/default add
DocumentRoot "RailsApp/public"
    # even only RailsApp also work

ProxyPass / balancer://localhost/
ProxyPassReverse / balancer://localhost/
< proxy balancer://localhost/ >
    BalanceMember http://localhost:3000
    BalanceMember http://localhost:3001
    BalanceMember http://localhost:3002
< /proxy >

Then set mongrel cluster
$ sudo gem install mongrel_cluster
$ cd RailsApp
$ mongrel_rails cluster::configure -e development -p 3000 -N 3
    # write config/mongrel_cluster.yml

$ mongrel_rails cluster::start

Final, restart apache2 and it work.


Thursday, April 17, 2008

rss feed in rails

Note for the Way to create Atom and RSS 2.0 feed.

$ ./script/generate controller feed

Suppose that the model we want show in feed is Post

class FeedController < ApplicationController
    def rss
        @rss = @@post

    def atom
        @atom = @@post

    @@post = Post.find :all,
        :order => "update_at", :limit => 10


Then write the view.


01 xml.instruct! :xml, :version=>"1.0"
02 xml.rss(:version=>"2.0"){
03     xml.channel{
04         xml.title("The site title")
05         xml.link(url_for("/"))
06         xml.description("The site description")
07         xml.language('en-us')
09         @rss.each do |rss|
10         xml.item {
11             xml.title rss.title
12             xml.link ""
13             xml.description rss.content
14             xml.pubDate rss.update_at
15             xml.guid ""
16             xml.author rss.declarer
17         }
18         end
19     }
20 }


01 xml.instruct! :xml, :version=>"1.0"
02 xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
03     xml.title("The site title")
04     xml.link(url_for "/")
05     @atom.each do |atom|
06         xml.entry {
07             xml.title(atom.title)
08             xml.summary(atom.content)
09         }
10     end
11 end

app/view/layout/application.rhtml add

<%= auto_discovery_link_tag :rss, { :controller => '/rss', :action => 'rss' }, { :title => "RSS 2.0" } %>
<%= auto_discovery_link_tag :rss, { :controller => '/rss', :action => 'atom' }, { :title => "Atom" } %>


Tuesday, April 15, 2008

rails helper block

Write for memo.
To set a helper in the form

<% helper_name do %>
<% end %>

The definition is

def helper_name(&block)
    content = capture(&block)
    concat("what we want write before block".block.binding)
    concat("what we want write after block",block.binding)

By the way, partial is the way do the same thing once. if the outer html is used frequently, the way to define a helper as above will be better.

Sunday, April 13, 2008


The rails plugin spakit means Single Page Application KIT. It can transform rails app into single page app but not modify app structure in large scale by loading content of other controller into primary controller.

The installation step is from handlino.com
$ sudo gem install spakit
$ cd railsapp/vendor/plugins/
$ gem unpack spakit
$ mv spakit-version spakit

now installation finished.

Before using it, spakit need a layout railsapp/app/view/layout/spakit.rhtml<%= flash[:notice] %>
<%= yield %>

And the layout application.rhtml should contain
<%= javascript_include_tag :defaults %> to include default js file.

Now we can use it happy. Add <div id="content"></div> into the view of primary controller, and set a spakit link: <%= spakit_link_to 'new person', :url => new_person_path %>, the content of the url will appear in the div#content.

Also two other helpers contain in spakit, spakit_form_for and spakit_form_tag

link1: spakit at rubyforge
link2: spakit at github

annotate models

The plugin used for adding column annotate into model file is introduced in Ralls Bible. Write for note. the newer introduction at http://pragdave.pragprog.com/pragdave/2006/02/annotate_models.html. Just two step to use it.
1.script/plugin install http://repo.pragprog.com/svn/Public/plugins/annotate_models
2. rake annotate_models
And all model now with column annotate at file head.

Saturday, April 5, 2008

.bashrc and screen on leopard

Leopard does not put .bashrc in user home directory as default. It is not convenient when using screen because screen only load ~/.bashrc but not /etc/bashrc. So copy the latter as my .bashrc.

debian package hyperlink

If writing <a href=”apt:package_name”>package_name</a> in html, On click the hyperlink, debian will install it.

openid resource

Report by solidot.org: openid resource. Noticeable point is blogger.com is one of the openid provider. It is a little surprising to me.

Monday, March 31, 2008

the rain

in my heart, in my heart...

the hope

on the cloud, on the cloud...

the dream

far away, far away...

the tomorrow

sing the same, sing the same...


Tuesday, March 25, 2008


I never notice that sqlite3 also support rc file. Write all convenient setting you like as ".header on"...etc in it. and never set it again when using sqlite3.

Sunday, March 16, 2008

the date you installed system

There is no specific log for the date you installed system. But two way to know it from other log. The one is find out the system installer log record what happened when the system be installed. in Debian, sudo head /var/log/installer/syslog could show the date. The second is find out the time the root partition be created. Suppose root partition is /dev/hda1, sudo tune2fs -l /dev/hda1 | grep create could show the date.

Saturday, March 15, 2008

sample yafc

yafc is very like lftp, but some different. yafc support Kerberos4, and it own better command interface more near unix command. for example, get -r could get a directory form remote, rm -r could remove directory from remote. But lftp support script input for using lftp -f script. The ability doesn't exist in yafc. Another ability more easy to use in yafc is customizing interface. It also work like unix shell. Use yafc --dump-rc > ~/.yafc/yafcrc to create a rc file, and modify the setting become your favorite type, so friendly.

link: yafc homepage

sample cftp

cftp is a full-screen console based ftp/sftp client, very easy to use for new user shift from windows need window based ftp client. But it is still need user understand some vi short key. Anyway, It still very helpful for new shift user. Just type in cftp -u username hostname to connect destination server. and use H, J, K, L could move within every directory. It is not famous in my friends maybe causing by its interface is not friendly with geek who work more effective in using ls, put, get :p.

link: cftp homepage

Sunday, March 9, 2008

tip for using space

It is very boring that using F8 to show all space partition and drag the window into another partition. Tonight the little discovery make me so happy. I just need to drag the window to the edge of desktop and double click the space key, and the window shift into the other partition beside the edge. Mac OS X is always make me amazing everyday. :D

Sunday, March 2, 2008

Taiwan High Speed Rail

Because of no motor transport ticket on sale, Today I am forced to take High Speed Rail when coming from Taipei. So that I eventually know the spelling of its name....so intuitive spelling. :p

Friday, February 29, 2008

colordiff and vim

Here mention a perl script package on Debian, colordiff. For highlighting output of diff just only pipe the output of diff to colordiff. For example, $ diff -rq /etc /var | colordiff | less -R or other similar commands as $svk diff | colordiff | less -R to get the highlighted. Otherwise we can use vim to got the same effect if syntax on has set in .vimrc. For example, $diff -rq /etc /var | vim -. Just only some difference between them. :p

Wednesday, February 27, 2008

Blueprint CSS 0.6 problem on IE

the class name "container" in IE have a problem: not align itself at center. Someway to fix it is set its parent element a property: { text-align: center; } to fix the problem.

Sunday, February 24, 2008

CPAN mirror SOP

3 steps note for how to mirror CPAN for fast installation in organization:

First, using rsync mirror whole CPAN to local machine. Write rsync -avHP --delete rsync.nic.funet.fi::CPAN /var/www/CPAN >> /var/log/rsync.log 2>&1 into crontab for daily synchronization. This step supposes mirror site root is put at /var/www/CPAN.

Second, write apache VirtualHost as below.
<VirtualHost *>
ServerName cpan.yourdomain

DocumentRoot /var/www/CPAN
<Directory />
Options FollowSymLinks
AllowOverride None
<Directory /var/www/CPAN/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

ErrorLog /var/log/apache2/cpan-error.log

LogLevel warn

CustomLog /var/log/apache2/cpan-access.log combined
ServerSignature On


Restart your apache and access cpan.yourdomain. you can see it.

Third, register your mirror site at mirrors.cpan.org if you want to become a official mirror site.


Saturday, February 23, 2008

Blueprint CSS 0.7.1 release

Quickly Note
There is many new feature in new release.New class name include alt, incr, quiet, small, large, showgrid...etc. Conversely, class name "column" is removed. Now div tag should be used as column. New directory structure come with new compressing ability through ruby script. Button's style move out from plugin and become an alone package put on download page

browser debuger note

Note for memory...

Safari include a build-in debug menu, but default is off. To enable debug menu, command "defaults write com.apple.Safari IncludeDebugMenu 1" in shell, restart Safari to load it.

Debug menu with a javascript console. use Firebug compatible function console.log and console.info can print some infomation in it

Regretfully, build-in javascript console is not with javascript shell. There is a nice alternative choice at here. drag the link named shell in this page to safari bookmark bar. Click the bookmark to got a javascript shell.

Firebug add-on is the better choice for looking DOM, CSS. It also with a nice build-in javascript shell.

Internet Explorer 7:
internet explorer developer toolbar is a new tool. It still in beta and only for IE7. Appearance looks like firebug, But without javascript shell and couldn't modify CSS in it. Any way, It shows some aurora for debugging javascript in IE. XD

More information in blog.gugod.org


Sunday, February 17, 2008

the end of winter recess

這個寒假比預期的廢了很多,預定的事項,想讀的書,沒一件做完的,再來,三月一日就是研究所考試了,看著別人即將踏入考場,自己摸著鼻子甸甸自己剩下不到一年的時間儲備,真是難以說話。雖然沒有完成預定的事項,不過練習 perl/ruby 之餘還是寫了些 bot,cwbbot 是個簡單的 ruby 天氣預報機器人,提供他 twitter 的帳號和密碼,丟進 crontab,就可以每天自動取得明日溫度。

Saturday, February 16, 2008

perl 和 ruby 的 twitter shell

twitter 最近紅透半邊天,perl 和 ruby 都有了 twitter api,現在還有 twitter shell,perl 的 twitter shell 利用 cpan 下 install Twitter::Shell 就可以得到 /usr/local/bin/twittershell, 使用方式為新增一個 yaml,如: touch ~/.twittershell.yml , 裡面填入
username: yourtwitteraccount
password: yourtwitterpassword
在 shell 下 twittershell -c ~/.twittershell.yml 就進入該 shell, help 可以得到幫助。

ruby 版本內建在 twitter 這個 gem 內, sudo gem install twitter 就可以得到 /usr/bin/twitter,直接在 shell 下 twitter 就可以得到幫助。不過 ruby 版本對 unicode 沒有支援,無法顯示中文,嘗試在 twitter gem 內的 twitter.rb 加入
require 'jcode'
$KCODE = 'u'
,不過沒有效果,作者也表示暫時不會加入 unicode 支援。

Friday, February 15, 2008

land mine in file name extension of ruby

和 perl 不同, ruby 的 third party module package, 也就是 gems, 副檔名和一般 script 都一樣是 ".rb", ruby 搜尋 module 的 path 似乎又包含了 ".", 所以如果使用的 script 檔名和 script 引用的 gems 內的檔名相同的話, 就會衝突 :/

Sunday, February 10, 2008

vim tab 功能

今天逛 Cornelius 時偶然發現 Vim tab 的功能,是 7.0 開始加入的新功能,使用感覺相當方便,基本用法如下:
:tabe filename 在新標籤頁打開一個檔案
:tabc 關閉標籤頁
:tabo 關閉其他標籤頁
:tabn 下一個標籤頁 或是 gt, C-PageDown
:tabp 上一個標籤頁 或是 gT, C-PageUp
:tabr 第一個標籤頁
:tabl 最後一個標籤頁
:tabs 顯示所有標籤頁
:tabm [N] 移動到第N順位
還可以 :set tabline 來定義 tab 顯示方式

Thursday, February 7, 2008


因為有個 js 檔是從 windows 上來的,要更換換行字尾,遍尋不到 dos2unix,這裡寫到和我一樣的遭遇,google 排名還滿前面,看來許多人都有同樣需求?需要的套件是 sysutils。

Sunday, January 6, 2008

aptitude tutorial

aptitude 是 sarge 之後建議的套件管理器, etch 之後應該是預設的,同時支援指令介面和文字 cursor 介面,是基於 apt-get 的模式發展的,我想他是想解決 apt 相關指令太過繁瑣的問題吧,另外也加上了自動解除不被相依套件的功能,以及 mutt-like 正規式搜尋的支援,後者還頗為重要,我想這是使 .deb 系統領先 .rpm 系統的關鍵(註:yum 管理器可以支援 shell 的 pattern 查詢,apt-cache 不支援任何 pattern),他也相容 dselect,可以說把 debian 之前的所有套件管理方式都包含進來,使用 aptitude 也一段時間了,不過最近才弄清楚他的特性。


首先,回顧一下 apt 套件管理器運作的方法,這在 aptitude 中也是一樣的,利用 /etc/apt/source.list 內指定的套件庫來源,aptitude 可以取得這些伺服器上準備好的套件列表,當然是有註記相依性在裡面,使用者只要指定要安裝的套件,aptitude 便會下載所有相依套件,交給 dpkg 解壓縮,配置到正確位置,和 apt 不同的是 aptitude 會將未被指定安裝,但相依性上需要而安裝的套件標記一個 A (Append),表示是個附加套件,當使用者移除當初指定安裝的套件時,如果附加套件沒有被其他套件相依,aptitude 便會移除他。

Interactive Interface

接下來來實際使用一下,先看比較簡單的互動式介面,在 shell 下直接輸入 aptitude 就可以得到文字 cursor 的介面。

1.資安更新 security update:這裡列出已經安裝且有更新的套件
2.新套件 new package:列出這次套件庫中的新套件,也就是之前不曾出現過的套件,按下 f 會將這些套件歸類為已知而不再出現在這裡,直到下次有新增套件才會羅列在此
3.已安裝套件 installed package:列出已經安裝的套件,而且都已經是最新版的
4.未安裝套件 not installed package:列出還未安裝的套件
5.過期的和自行建立的套件 obsolete and locally created packages:已安裝的套件但沒有出現在套件庫的
6.虛擬套件 virtual package:虛擬套件指的是一個邏輯上的套件名稱,這些套件實際上會由其他套件提供,例如 mail-transport-agent 由 postfix, sendmail, exim 來提供
7.作業 task:有點類似 deselect,利用預定義的方式安裝特定任務套件,還可以利用 .aptitude 檔案對任務進行瀏覽和安裝

文字 cursor 介面使用方式非常直覺,進入後第一件是就是按下 u 來更新套件庫資訊,利用 Ctrl-t 來選擇上方選單標定套件要進行的動作,最後按下 g 就可以得到想要的效果,如果嫌太麻煩,選單旁邊還有標示快速鍵,其中有許多快速鍵是支援 vi 模式的,例如按下 / 就可查詢,查詢完按 n 可以跳到下一個符合項目,上下方向鍵也是,其中最重要的當然是標定哪些套件要安裝/移除的快速鍵,分別是 + 和 - ,標定好狀態後按下 g,就會執行更動。常用的快速鍵列表有:

F10:和 Ctrl-t 一樣顯示 menu
Enter 觀看套件內容
q 離開這個頁面,在主頁面按下會離開 aptitude

/ 搜尋
\ 反向搜尋 (這項在 debian reference 內寫錯)

g 執行所有套件異動
+ 將套件標記為新安裝或更新
- 將套件標記為要移除,此選項會保留組態檔
_ 將套件標記為清除,包含組態檔也刪除
= 將套件標記為固定
: 在此次執行期間鎖定該套件

U 將所有可升級套件標記為升級
C 觀看套件變更紀錄
L 將套件標示為重新安裝
R 將套件標示為重新配置

Command Line Interface

不過對於習慣在文字介面下過活的人,上述方法未免太痛苦了:D,aptitude 提供的強大 command line,可以讓你更快速達到目的,而且和 apt 系列指令基本上相容,具官方說法,aptitude 和 apt-get 管理不同資料庫來維護相依性,實際上使用,apt-get 和 aptitude 可以看到彼此安裝的套件。

aptitude 的命令形式為 aptitude action [argument],如 aptitude update,使用 update 這個 action 指示更新最近套件列表,可用的 action 為:

update 從來源處更新套件列表
upgrade 更新所有資安更新
dist-upgrade 更新所有版本更新

search pattern1 [pattern2...] 搜尋滿足樣式的套件
show package1 [package2...] 顯示套件資訊
changelog 顯示套件更改紀錄

install package1 [package2...] 安裝套件
reinstall package1 [package2...] 再次安裝套件
remove package1 [package2...] 移除套件
purge package1 [package2...] 清除套件

download 下載套件的 .deb 檔案
clean 刪除已下載的套件檔案
autoclean 刪除舊的已下載的套件檔案

hold 將套件標示為保持狀態
unhold 取消對一套件的保持命令

markauto 將套件標記為自動安裝
unmarkauto 將套件標記為手動安裝

forbid-version 禁止升級特定的套件版本
forget-new 將新套件辨識為已知套件

可用的 argument 請自行參閱 aptitude -h 所顯示的內容,可最為命令時的輔助用。

~ahold 代表標示為保持現狀的套件
~b 為損壞套件
~g 無用的套件
~c 未清除的套件
~d{text} 描述中含有{text}的套件
~m{maintainer} 由指定維護者維護的套件
~V{version} 版本號{version}的套件


# aptitude purge ~g

這樣的命令,就會清除系統內所有無用的套件,這個功能在 deborphan 套件內也有提供且更為強大,但 aptitude 這樣的整合提供了很高的便利性。


# aptitude install A+ B- C_ D=


Tag Definition

無論利用 aptitude 瀏覽套件庫或是使用文字介面查詢,可以看到每個套件前面標示有一些 tag,標示套件目前的狀況或種類:
p 已清除或未安裝的
v 虛擬套件
B 損壞
u 已由 dpkg 解開
C 配置到一半的的
H 安裝到一半的的
c 移除 (remove) 但尚未清除 (purge) 組態的
i 已經安裝的
E 內部錯誤的


OK,寫程式總是要來點樂趣,可是寫這種套件管理程式哪有什麼樂趣可言,又是正規式又是相依性的,那...作者到底在哪裡找樂趣呢?如果你仔細瞧瞧 aptitude -h 所顯示的幫助頁面,會發現在最後一行有個 "這個 aptitude 沒有超級牛力 (This aptitude does not have Super Cow Powers.)",如果你有用過 apt-get,那還會發現 apt-get -h 所顯示的幫助頁面最後一行有個 "這個 apt 有著超級牛力 (This APT has Super Cow Powers.)",什麼是超級牛力呢?嘿嘿,超級牛力是 debian 系統中一股神秘的力量喔~。請試著鍵入

# aptitude moo

有東西嗎?那...再多加個 -v 進去看看。
哈哈,你肚子痛了嗎?那...再多加幾個 v 看看XD。

Reference Document

[1] aptitude 簡明手冊
[2] debian reference
[3] aptitude user manual
第[2],[3]項在 debian 上分別為 debian-reference-zh-tw, aptitude-doc-en 這兩個套件


寫這篇大概寫了我五六個小時不只,剛開始寫真的沒想到會寫這麼久阿。我可以了解 Rails 聖經作者 Dave Thomas 說 "我每寫一本書,就發誓這是最後一本了" 的心情:D

Saturday, January 5, 2008

debian 上的 apache2 manual

適才偶然發現了 debian 上的一個 apache 小秘密,還頗有趣的。

事實上,debian 上的軟體很多都有提供 xxx-doc 這樣的文件套件,安裝位置都在 /usr/share/doc/ 底下,apache2 也不例外,預設上 /etc/apache2/site-available/default 這個 site configure file 是有 alias /doc /usr/share/doc 這樣的配置,所以雖然我有裝了apache2-doc,一直以來我也都是連到 http://mymachine/doc/ 來看的。不過 apache2-doc 提供的 html doc 就是特別奇怪,連結都連結不好,所以我都會重新配置檔案,copy 一份 en 的到特定資料夾,這樣才會比較正常。

但沒想到這份文件其實提供了一個 configure 在 /etc/apache/conf.d/apache2-doc,cat 一下這個檔案,會發現裡面寫好了 /manual 這個 alias 並且做了一些 redirection 來符合文件內的超連結。所以其實連到 http://mymachine/manual/ 就可以正常觀看。