iPodから送信
Friday, October 31, 2008
Wednesday, October 29, 2008
Ruby observerパターン
1 module Observable
2 def add_observer(observer)
3 @observers ||= []
4 @observers << observer
5 end
6
7 def notify_observers(*objs)
8 @observers.each do |obs|
9 obs.update(*objs)
10 end
11 end
12 end
13
14 class Tick
15 include Observable
16 def start
17 loop do
18 now = Time.now
19 notify_observers(now.hour, now.min, now.sec)
20 sleep 0.9
21 end
22 end
23 end
24
25 class Clock
26 def update(h, m, s)
27 printf "\e[8D%02d:%02d:%02d", h, m, s
28 STDOUT.flush
29 end
30 end
31 tick = Tick.new
32 tick.add_observer(Clock.new)
33 tick.start
Tuesday, October 28, 2008
Monday, October 27, 2008
Ruby Observer PartI
1 #!/usr/local/bin/ruby
2 # encoding: utf-8
3 class Ticker
4 def start
5 loop do
6 price = StockPrice.price
7 print_price(price)
8 print warn_price(price)
9 sleep 1
10 end
11 end
12 def print_price(price)
13 printf "%.02f\n", price
14 end
15 def warn_price(price)
16 if price > 140
17 "High\n"
18 elsif price < 60
19 "Low\n"
20 end
21 end
22 end
23 class StockPrice
24 def self.price
25 (rand * 100) + 50
26 end
27 end
28 ticker = Ticker.new
29 ticker.start
Saturday, October 25, 2008
Friday, October 24, 2008
Ruby Distributed Ruby
Ruby method再定義
class Example
alias_method old_reverse reverse
def reverse
result = old_reverse
....
end
end
class Example
old_reverse_method = instance_method :reverse
define_method :reverse do
result = old_reverse_method.bind(self).call
.....
result
end
end
Tuesday, October 21, 2008
Sunday, October 19, 2008
Ruby Hook Method list
[Method-related hooks]
method_missing, method_added, singleton_method_added, method_removed, single-ton_method_removed, method_undefined, singleton_method_undefined
[Class and module-related hooks]
inherited, append_features, included, extend_object, extended, initialize_copy, const_missing
[Object marshaling hooks]
marshal_dump, marshal_load
[Coercion hooks]
coerce, induced_from, to_xxx
Wednesday, October 15, 2008
Amazon VS Yahoo! Auction
- 月会費294円
- 落札価格の5.25%(税込)
- 月10回以上の出品で10.50円×個数
- 配送料が落札者持ちなら0円
- 成約料100円
- 販売価格の15%(エレクトロニクスは10%)
- 実際の配送料とアマゾンからの支給額の差額(下表参照)
- ヤフオク:1,081.5円(294+787.5)=>利益:13,918.5円
- アマゾン:2,950円(100+2250-140+送料740)=>利益:12,050円
- 差額:1,868.5円
- ヤフオク:399円(294+105)=>利益:1,601円
- アマゾン:670円(100+300-80+送料350)=>利益:1,330円
- 差額:271円
| 配送料の欄に 表示される金額 | 配送料から差し引かれる金額 | 出品者が受け取る実際の配送料 | |
| 本 | ¥340 | ¥80 | ¥260 |
| CD&レコード | ¥340 | ¥140 | ¥200 |
| ビデオ | ¥380 | ¥30 | ¥350 |
| DVD | ¥340 | ¥140 | ¥200 |
| ソフトウェア | ¥340 | ¥140 | ¥200 |
| ゲーム | ¥340 | ¥140 | ¥200 |
| エレクトロニクス | ¥450+¥50/kg | ¥90+¥10/kg | ¥360+¥40/kg |
| ホーム & キッチン | ¥450+¥50/kg | ¥90+¥10/kg | ¥360+¥40/kg |
| おもちゃ & ホビー | ¥500 | ¥100 | ¥400 |
| スポーツ | ¥500 | ¥100 | ¥400 |
| ヘルス & ビューティー | ¥500 | ¥100 | ¥400 |
Tuesday, October 14, 2008
株式市場に嵐が吹き荒れている

Ruby metaprogramming - create Class Methods
1 #!/usr/bin/env ruby
2 # encoding: utf-8
3 class Creature
4 def self.atta(arg)
5 metaclass = class << self
6 self
7 end
8 metaclass.class_eval do
9 define_method(arg) do |val|
10 eval("@#{arg}=#{val}")
11 end
12 end
13 end
14 atta :life
15 end
16
17 class Dragon < Creature
18 life 100 # => 100
19 @life # => 100
20 end
21 Dragon.singleton_methods # => ["life", "atta"]
22
Ruby metaprogramming accessor
1 #!/usr/bin/env ruby
2 # encoding: utf-8
3 class Creature
4 def self.atta(*arg)
5 arg.each do |arg|
6 define_method(arg) do
7 instance_variable_get("@#{arg}")
8 end
9 define_method("#{arg}=") do |val|
10 instance_variable_set("@#{arg}", val)
11 end
12 end
13 end
14
15 end
16
17 class Dragon < Creature
18 atta :life
19 end
20 d = Dragon.new
21 d.life = 20
22 d.life # => 20
23
Saturday, October 11, 2008
iPodTouch保護フィルム
fring with iPod Touch
Monday, October 06, 2008
iPod Touch
- いろいろできることで却ってなんか落ち着かない
- 余計な仕事を増やしてる感じ
- 裏も表も指紋でべったり
- Webを見るのはちょっとつらい
- メールやRSSなどのリストものは見やすい
- 音が思ってたよりいい
- YouTubeなどの動画が見やすい
- メールに添付したPDFは一旦アクセスすればオフラインでも閲覧できる
- ジーンズのポケットに入れられるサイズ
Sunday, October 05, 2008
iPod Touch遂に現わる!
Inkjet Printerのインク交換
Thursday, October 02, 2008
Unix/Linuxプログラミング 理論と実践
すべてのクラスの取得
klasses = []ObjectSpace.each_object do |obj|beginklasses << obj if obj.superclassrescue Exception => eendendp klasses
Wednesday, October 01, 2008
gOSにRuby1.9をインストール
sudo apt-get install subversionsudo apt-get install autoconf bison -y svn co http://svn.ruby-lang.org/repos/ruby/trunk ruby cd ruby autoconf ./configure --prefix=/usr/local --program-prefix=_ make sudo make install


