顯示包含「ruby」標籤的文章。顯示所有文章
顯示包含「ruby」標籤的文章。顯示所有文章

12/30/2009

[Ruby] string format

"%.3f" % (1.0/7) # "0.143"
"%5.1f" % 345.6789 # "345.7"

"%05d" % 123 # "00123"
"%-5s" % "ID" # "ID "
"%04x" % 0xfc14 # "fc14"

"%6.2f, %05d" % [345.6789,123] # "345.68, 00123"
"%-5s: %04x" % ["ID", 0xfc14] # "ID : fc14"

11/14/2009

codeploy? It's hard to use it

Recently, I tried to use codeploy to upload my program to many planetlab nodes.
But seeing the setting instruction, it's too inconvenient.
There are too many parameter to set.
So I write a simple ruby script to implement this multiple upload function.

usage: ./multi-upload directly_you_want_to_upload

script:

#! /usr/bin/ruby

arr = IO.readlines("node_list")
arr.each { |x|
puts "node name:#{x.chomp}"
cmd = "scp -r #{ARGV[0]} ACCOUNT@#{x.chomp}:/home/ACCOUNT"
puts `#{cmd}`
}

See, 9 lines code can do the same thing.
Why don't use it?