วันอาทิตย์, เมษายน 20, 2551

เห็นเล่นกันพักใหญ่แล้ว...
ขอแป๊ะไว้บ้าง เดี๋ยวตกเทรนด์


ว่างจัดเป็น chart สวยงาม


เขียนด้วย Ruby เผื่อใครอยากเล่น

1 #history.rb
2
def run(command)
3 IO.popen(command, 'r+') do |io|
4 io.close_write
5 return io.read
6 end
7 end
8
9 commands = {}
10 history = run("cut -f1 -d' ' /Users/zdk/.bash_history | sort | uniq -c | sort -nr | head -n 10")
11 history.each do |line|
12 tmp = line.strip.split
13 key = tmp[1]
14 value = tmp[0]
15 commands[key] = value unless key.nil? or value.nil?
16 end
17
18 base_url = "http://chart.apis.google.com/chart?cht=p3&chd=t:"
19 names = commands.keys * "|"
20 freqs = commands.values * ","
21 chart_size = "&chs=250x100&chl="
22
23 url = base_url
24 url << freqs + chart_size + names
25
26 puts url