對抗垃圾信!請您點這裡:

我的E-mail:
我的Skype:My status

2006年10月10日

1.hours

我絕對沒有唬爛
這件事情是真的
如果你有裝Rails
請開啟irb,依照下列步驟code

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'active_support'
=> true
irb(main):003:0> puts 1.hours
3600
=> nil
irb(main):004:0> puts 1.minutes
60
=> nil
irb(main):005:0> puts 1.seconds
1
=> nil
irb(main):006:0> puts 1.years
31557600
=> nil
irb(main):007:0> puts 1.days
86400
=> nil
irb(main):008:0>

該死
這讓我回想起當初在寫PHP的Wretch Blog RSS Reader時,在判斷檔案建立時間的部份寫得多痛苦
這麼直覺化的東西.. 就算會讓我腦殘我也要去用.. Orz

Google Gadget for HEMiDEMi

葛力~ 葛力~ 葛力葛力葛力~ 好吃拉XD... 不對= ="
各位Google Fans + 黑咪飯團重度愛好者們,現在HEMiDEMi推出Google Gadget拉!!!
所以可以很方便的就在Google個人化首頁或者Google Desktop上使用喔!
那說得這麼好聽,到底要怎樣加入呢?
來來來,網址底加拉!!!
請按此
預設只會顯示3個書籤,請加入後按下編輯改成9個(最多只能9個了....)

有任何問題記得回覆一下唷!

2006年9月4日

Hemidemi群組最新書籤 0.0.0.2 版

這次的這個版本,則是將 "最新書籤(整個網站)", "使用者最新書籤", "群組最新書籤" 3個合併囉
也就是說,使用者只要下參數,就可以抓到資訊了!
參數:

$ ruby ./recent.rb [要抓的資訊] [要顯示的書籤量] [名稱]

* 整個程式省略掉參數的話,就是整個網站的最新書籤

要抓的資訊:
0: 整個網站的最新書籤
1: 使用者最新書籤
2: 群組最新書籤

這個版本還沒有Method overload... 因此沒有辦法省略掉其中的幾個參數..
未來版本會修正這個問題
程式碼如下:

#!/usr/bin/env ruby
# Code by CFC Zuso Security
# # Taiwan Ruby Users Group: http://www.ruby.oss.tw/
# # Rails Taiwan: http://www.rubyonrails.org.tw/
#
# Hemidemi bookmarks loader: Ver. 0.0.0.2 Beta
#
#==========
#
# 1. Recent: http://www.hemidemi.com/rss/bookmark/recent.xml
# 2. User's recent: http://www.hemidemi.com/rss/user/#{@usr_name}/bookmark/recent.xml
# 3. Group's recent: http://www.hemidemi.com/rss/group/#{@grp_name}/bookmark/recent.xml
#
#==========
#

require 'rexml/document'
require 'open-uri'
include REXML

class Recent
def initialize(opt, count, name)
case opt.to_i
when 0
@url = "http://www.hemidemi.com/rss/bookmark/recent.xml"
when 1
@url = "http://www.hemidemi.com/rss/user/#{name}/bookmark/recent.xml"
when 2
@url = "http://www.hemidemi.com/rss/group/#{name}/bookmark/recent.xml"
else
@url = "http://www.hemidemi.com/rss/bookmark/recent.xml"
end
@channel = @channel || {}
@items = []
if count == nil
@count = 6
else
@count = count.to_i
end
end

def run
load_in
show
end

def load_in
open(@url) do |f|
xml = Document.new(f.read)

xml.elements.each("*/channel") do |chnl|
@channel["name"] = chnl.elements["description"].text
@channel["link"] = chnl.elements["link"].text
end

xml.elements.each("*/channel/item") do |item|
itm = {}
itm["title"] = item.elements["title"].text
itm["description"] = item.elements["description"].text
itm["link"] = item.elements["link"].text
itm["creator"] = item.elements["dc:creator"].text
@items << itm
end
end
end

def show
line = "=" * 100
puts @url
puts line
puts "#{@channel["name"]} [ #{@channel["link"]} ]"
puts "共有#{@items.size}個書籤"
puts line
@count = @items.size if @items.size < @count
@count.times { |cnt|
puts "張貼者:#{@items[cnt]["creator"]} [ http://www.hemidemi.com/user/#{@items[cnt]["creator"]}/home ]"
puts "標題:#{@items[cnt]["title"]}"
puts "網址:#{@items[cnt]["link"]}"
puts "敘述:#{@items[cnt]["description"]}"
puts "-"*10
}
puts line
end
public :run
private :load_in, :show
end

rss = Recent.new(ARGV[0], ARGV[1], ARGV[2])
rss.run

下載點:
http://stmail.tajen.edu.tw/~593092514/recent.rb

Hemidemi群組最新書籤 -- Console版

哇哇哇
http://flickr.tw的站長推出這麼棒的Hemidemi hacking...
只是小弟遜咖,沒辦法像他那樣>"<
好吧.. 我只好寫個個人用的小工具
這個程式是適用於群組的,一般來說群組都會有最新書籤,而這個是將最新書籤印出來的..
程式只能跑在純文字模式下..
輕巧咩~另外網管如果沒有在管沒有X Window的主機時,也可以用這個拉!
Usage: $ ./grp_recent.rb group_name [count]
Options: * group_name: 沒錯!就是群組名稱!
* count: 可省略參數,用於顯示幾個書籤(從最新的開始算起,預設是6個)
程式碼如下:
#!/usr/bin/env ruby
# Code by CFC Zuso Security
# Taiwan Ruby Users Group: http://www.ruby.oss.tw/
# Rails Taiwan: http://www.rubyonrails.org.tw/
#
require 'rexml/document'
require 'open-uri'
include REXML

class Recent
attr_accessor :grp_name, :channel, :items

def initialize(grp_name, count)
@grp_name = grp_name
@url = "http://www.hemidemi.com/rss/group/#{@grp_name}/bookmark/recent.xml"
@channel = @channel || {}
@items = []
if count == nil
@count = 6
else
@count = count.to_i
end
end

def run
load_in
show
end
def load_in
open(@url) do |f|
xml = Document.new(f.read)

xml.elements.each("*/channel") do |chnl|
@channel["name"] = chnl.elements["description"].text
@channel["link"] = chnl.elements["link"].text
end

xml.elements.each("*/channel/item") do |item|
itm = {}
itm["title"] = item.elements["title"].text
itm["description"] = item.elements["description"].text
itm["link"] = item.elements["link"].text
itm["creator"] = item.elements["dc:creator"].text
@items << itm
end
end
end

def show
puts "="*10
puts "群組:#{@channel["name"]} [ #{@channel["link"]} ]"
puts "共有#{@items.size}個書籤"
puts "="*10
@count = @items.size if @items.size < @count
@count.times { |cnt|
puts "張貼者:#{@items[cnt]["creator"]} [ http://www.hemidemi.com/user/#{@items[cnt]["creator"]}/home ]"
puts "標題:#{@items[cnt]["title"]}"
puts "網址:#{@items[cnt]["link"]}"
puts "敘述:#{@items[cnt]["description"]}"
puts "*"*10
}
puts "="*10
end
public :run
private :load_in, :show
end

rss = Recent.new(ARGV[0], ARGV[1])
rss.run

下載點:http://stmail.tajen.edu.tw/~593092514/grp_recent.rb

2006年8月24日

Rails + AJAX範例

這網站看起來真不錯:P
網址:http://demo.script.aculo.us/

裏面有幾個不錯的Demo
而且都有釋出原始碼

用Rails真的很快Orz..
像是第一個範例
Autocompleting text fields (basic)

程式碼兩行(一行在view,一行是controller)就搞定

第二個也是扯
上面
To:那邊輸入A
CC:輸入B
輸入一個字後先等著不要離開,它就會出現suggestion了..

hmmm... 真是好玩!

2006年8月22日

Ubuntu -- 更新系統後進不去X Window

早上要去學校前,更新了一下xserver-xorg-core
剛回到家發現.. X進不去了!?
怪.. 用laptop上IRC後發現也有其他人這樣
卻不知道是那邊出問題..
上了論壇,一樣有這問題的求助文章
上去Cn那邊.. 也是有.. 可是都沒有解答
好吧.. 去美國看看
看完後,找到解決方案... 底下是步驟

根據以下指令動作
wget -c http://people.ubuntu.com/~rodarvus/packages/dapper/xorg-server/xserver-xorg-core_1.0.2-0ubuntu10.4_i386.deb
wget -c http://people.ubuntu.com/~rodarvus/packages/dapper/xorg-server/xserver-xorg-dev_1.0.2-0ubuntu10.4_i386.deb
抓完後,請下 dpkg -i xserver-xorg*
如果說,xserver-xorg-dev安裝失敗也沒關係
我想應該沒有什麼影響
然後裝好後就可以 sudo /etc/init.d/gdm restart
接著就可以進去X了!

2006年8月21日

如何進去網站後就轉到指定的Controller?

嗯.. 關於這點..
呵~cookoo大哥先在這邊謝過拉XD
雖然你忘記要作最後一個動作...

ok...

  1. edit config/routes.rb
  2. add map.connect '', :controller => "ctrl_name"
  3. save it and remove or rename public/index.html
cookoo大哥忘記說哪一點呢?
沒錯...
第三點="=

害我昨天測試了老半天阿阿阿阿阿阿阿阿阿!!!!!!!