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

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

2006年10月10日

又是Ruby一行文... 畫出一張圖

請在命令提示字元或者虛擬終端機下執行以下指令(請記得安裝Ruby)

ruby -e "32.times{|y|print\" \"*(31-y);(y+1).times{|x|print\" #{~y&x==0?\"A\":\".\"}\"};puts}"

Pool wretch.. XD

看看底下的圖片吧

我不想多說XDDDDD



 

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... 真是好玩!