Monday, June 30, 2008
Gmailをふつうのアプリケーションのように使う
GmailやGoogleCalendarなどのWebアプリを
ローカルのアプリケーションのように使えるようにするものだ
Sunday, June 29, 2008
日本語変換文字化け?
日本���MacUIM
Saturday, June 28, 2008
Ruby Hilite.rb
fact.js with slush_poppies
1 var fact = function(n) {
2 if(n==0) {
3 return 1;
4 } else {
5 return n * arguments.callee(n-1);
6 }
7 }
fact.pl with spacecadet
1 sub fact {
2 my($n) = @_;
3
4 if ($n == 0) {
5 return 1;
6 } else {
7 return $n * fact($n - 1);
8 }
9 }
10
11 printf "%d! = %d\n", 10,fact(10);
12
fact.py with amy
1 def fact(n):
2 if n == 0:
3 return 1L
4 else:
5 return n * fact(n - 1)
6
7 print "%d! = %s" % (10, fact(10))
fact.rb with brilliance_dull
1 def fact(n)
2 if n == 0
3 1
4 else
5 n * fact(n - 1)
6 end
7 end
8
9 printf "%d! = %d\n", 10, fact(10)
fv.rb
1 #!/opt/local/bin/ruby -Ku
2 #
3 # FV = PV(1+r)^n
4 #
5
6 class FCalc
7 def fv(pv,r,n)
8 pv*(1+r)**n
9 end
10 def pv(fv,r,n)
11 fv/(1+r)**n
12 end
13 end
14
15 f = FCalc.new
16 p fv = f.fv(100,0.1,10)
17
18 11.times { |n| p "year #{n}: #{f.fv(100,0.1,n)}" }
Monday, June 23, 2008
TextMate:Create Snippet
- -plain text: just insert text
- -variables: $TM_SELECTED_TEXT
- -variables with default: ${TM_SELECTED_TEXT:default text}
- -variables with regexp: ${TM_SELECTED_TEXT/regexp/format/options}
- ex. ${TM_SELECTED_TEXT/w+/<$0>/g}
- -Shell Code Insertion: ex. <a href="`pbpaste`">$TM_SELECTED_TEXT</a>
- -Tab Stops: $0 or $1..$n
- -Tab Stops with Default(Placeholders): ${1:default}
- -Mirrors: ex. <${1:div}> $0 </$1>
- -Transformations: ${1/regexp/format/options}
- -Transformations with condition: ${1/x$|(.+)/(?1:other)/}
- -Cascading placeholders: ${1:default${2:default}}
Sunday, June 22, 2008
Saturday, June 21, 2008
TextMate Tips: excute code
- Run code: ⌘+r
- Ruby in line evaluation with # => , ⌘⌃ +E
- same without # =>, ⌘⌃+E
- excute line as Ruby: ⌃+E
- excute line as shell: ⌃+r
TextMate mate command
$ sudo ln -s /Applications/TextMate.app/Contents/Resources/mate ~/bin/mate
Friday, June 20, 2008
Ruby Pastie.rb syntaxhighlight
- 各テーマのbackground-colorとcolorプロパティがUv側から取得できていない。
- 替わりに、ハッシュで設定ファイルを作ってこれを読むようにしている。
- Cobalt以外のテーマのこれらのプロパティ値がいまのところ不明。
1 #!/usr/bin/env ruby -wKU
2 # encoding: utf-8
3 require "rubygems"
4 require "uv"
5
6 theme_colors = {"active4d" => [], "all_hallows_eve" => [],
7 "amy" => [], "blackboard" => [],
8 "brilliance_black" => [], "brilliance_dull" => [],
9 "cobalt" => ['#002444','#e6e1dc'], "dawn" => [],
10 "eiffel" => [], "espresso_libre" => [],
11 "idle" => [], "iplastic" => [],
12 "lazy" => [], "mac_classic" => [],
13 "magicwb_amiga" => [], "pastels_on_dark" => [],
14 "slush_poppies" => [], "spacecadet" => [],
15 "sunburst" => [], "twilight" => [],
16 "zenburnesque" => []}
17
18
19 input = ARGF
20 theme = "cobalt"
21 syntax = "ruby"
22 numbering = true
23
24 html = Uv.parse( input, "xhtml", syntax, numbering, theme )
25
26 css_file = File.join(Uv.path, 'render', 'xhtml', 'files', 'css', "#{theme}.css")
27
28 styles = {}
29 css = open(css_file, 'r').read
30 css.gsub(/pre¥.#{theme}¥s+¥.(¥w+)¥s+¥{¥s*(¥w+.*¥s*¥w*.*)¥s*¥}/) do
31 styles[$1] = $2.gsub(/¥s/, "")
32 end
33 styles["#{theme}"] = %Q{background-color:#{theme_colors[theme][0]};color:#{theme_colors[theme][1]}}
34
35 styles.each do |key, value|
36 html.gsub!(/class="#{key}"/i, %Q{style="#{value}"})
37 end
38 puts html
Thursday, June 19, 2008
Ruby code colorize 3
$ ruby pastie.rb rubyfile.rb > target.html
1 #!/usr/bin/env ruby -wKU
2 # encoding: utf-8
3 require "rubygems"
4 require "uv"
5
6 themes = %w(active4d all_hallows_eve amy blackboard brilliance_black
7 brilliance_dull cobalt dawn eiffel espresso_libre idle
8 iplastic lazy mac_classic magicwb_amiga pastels_on_dark
9 slush_poppies spacecadet sunburst twilight zenburnesque)
10
11
12 input = ARGF
13 theme = "cobalt"
14 syntax = "ruby"
15 numbering = true
16 css_file = "/opt/local/lib/ruby/gems/1.8/gems/ultraviolet-0.10.2/render/xhtml/files/css/#{theme}.css"
17
18 html = Uv.parse( input, "xhtml", syntax, numbering, theme )
19
20 #link = %Q(<link rel="stylesheet" href=#{css_file} type="text/css" media="screen" title="no title" charset="utf-8">)
21
22 css = open(css_file).read
23 style = %Q(<style type="text/css" media="screen">
24 #{css}
25 </style>)
26
27 puts style + html
Ruby code colorize 2
$ uv -s ruby -t cobalt -c . rubyfile.rb > target.html
<link rel="stylesheet" href="css/cobalt.css" type="text/css" media="screen" title="no title" charset="utf-8">
Ruby code colorize
1 #!/usr/bin/env ruby -wKU
2 # encoding: utf-8
3 require "rubygems"
4 require "uv"
5
6 BACKGROUND_COLOR = '#002444'
7 COLOR = '#e6e1dc'
8 COLORS = {
9 # :punctuation => '#E1EFFF',
10 :constant => '#FF628C',
11 :entity => '#FFDD00',
12 :keyword => '#FF9D00',
13 :storage => '#FFEE80',
14 :string => '#3AD900',
15 :comment => '#0088FF',
16 :support => '#80FFBB',
17 :variable => '#CCCCCC',
18 :symbol => '#6e9cbe',
19 :JEntityNameType => '#FFDD00',
20 :attribute => '#d0d0ff',
21 :StringRegexp => '#80FFC2',
22 :StringEmbeddedSource => '#FFFFFF',
23 :exception => '#FF1E00',
24 :function => '#FFEE80'
25 }
26 html = Uv.parse(STDIN.read, "xhtml", "ruby", true, 'cobalt')
27
28 COLORS.each do |token, color|
29 html.gsub!(/class="#{token}"/i, %Q{style="color:#{color}"})
30 end
31 puts %Q(
32 <pre style="background-color:#{BACKGROUND_COLOR};
33 color:#{COLOR};
34 padding:3px 0 3px 0;
35 overflow:auto;
36 line-height:15px;
37 font-size:13px";>
38 <code>#{html}</code>
39 </pre>
40 )
Wednesday, June 18, 2008
Ruby メタプログラミング define method
Output:
|
Tuesday, June 17, 2008
Ruby 再帰の結果を配列に入れる
死の被害者
はちみつ協定、締結!
Monday, June 16, 2008
我らただいま実験中!
Rails Portfolio進捗状況
- Hpricotを使ってInfoseekのサイトから株価および企業情報を取得
- 取得した情報に基づいて利益などのポートフォリオ情報を計算
- 計算結果と情報を表形式で表示
- ポートフォリオ情報と企業情報をタブで切替え
- タブ切替えはPrototypeのVisualEffectを使用
- 取得した時系列株価を整理して、月、週、日ごとの株価の表を登録銘柄について比較表示
- OpenFlashChartを使って個別銘柄の株価チャートを表示
- データベースと連携して取得したデータを保存すること
- 利益などのポートフォリオ情報の変動を示すグラフ
- 株価の変動と当期利益の変動の関係を示した二軸チャートの作成(出来れば対数グラフ)
- 更に進んで資産管理データベースの作成
Sunday, June 15, 2008
イヤホンで恐ろしく迷う
価格 | 付属品 | プラグ | ケーブルタイプ | ケーブル長 | 音 | ブランド | |
---|---|---|---|---|---|---|---|
ゼンハイザーCX300 | 3,900 | 無し | L型 | U型 | 0.85 | △ | ◎ |
CreativeEP630 | 2,500 | 無し | ストレート/メッキ | Y型 | 1.2 | ◎ | △ |
Sumajin/SUMEAR | 4,212 | コードマネージャ/ポーチ/AirplaineAdapter | L型メッキ | U型 | 1.33 | ◎ | △ |
iSonic/mimisen | 2,980 | キノコ/ポーチ/iPod用ストラップ | ストレート/メッキ | Y型 | 1.2 | ? | × |
これがワレの生き方じゃ!その1
- 寿命が伸びた現代では、年齢を2で割ってちょうどよい。
- 他人の評価は重要ではない。重要なのは自分がそれを楽しめているかだ。
- 人間の脳は思いの外考えるのが苦手である。
- 脳は良い出来事よりも悪い出来事のほうをより鮮明に記憶する。
- 健康のためには食べてはいけない。
- 肥満は自殺行為である。
- 人生は本質的にはつまらないものである。
- 人生を壮大なる実験と考えたほうがよい。
- 大抵の問題の原因は自分にある。
- 人は鎖を解かれても先の見えない恐怖から自ら奴隷になる。
Saturday, June 14, 2008
Rails Tab
- フェードエフェクトでタブを切替え
- タブにlink_to_remoteを貼り、これでrjsファイルを呼び出し、部分テンプレートを読むようにする
- rjsファイルを呼び出す際に:idパラメータを渡し、それで表示する部分テンプレートを切り替えるようにする
- link_to_remoteに部分テンプレートで表示する情報を:stocksパラメータとして渡す
- rjsでは既に表示されているDOMをfadeし、delayした後、replace_html, appearする。
- link_to_remoteがパラメータとしてobjectを渡せずstringかarrayしか渡せないようなので、helperで予め渡すオブジェクトから要素を抜き取って配列とした点。
- rjsで、シリアルにfade, appearとしてもうまくいかず、delayを挟んだ点。
page[:panel].visual_effect :fade, :duration => 1.0page.delay(1) docase params[:id]when '1'page[:panel].replace_html :partial => 'panel1'page[:panel].visual_effect :appear, :duration => 1.0when '2'page[:panel].replace_html :partial => 'panel2'page[:panel].visual_effect :appear, :duration => 1.0endend
Friday, June 13, 2008
Rails Tab
Wednesday, June 11, 2008
Rails session
config.action_controller.session_store = :active_record_store
rake db:sessions:create
rake db:migrate
Tuesday, June 10, 2008
Rails parameter passing
Rails page cache
caches_page :index, :view
config.action_controller.perform_caching = true
Sunday, June 08, 2008
Ruby Stock
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #!/usr/bin/env ruby -wKU # encoding: utf-8 require "rubygems" require "hpricot" require "open-uri" require "kconv" class Stock attr_reader :name, :category, :data, :price_data, :credit_data, :company_data, :value_data def initialize(code) @code = code main_data(@code) end
def price_history(term,method='m',start_page=0) #method:m,w,d, sstart_page:0,50,100 begin url = "http://money.www.infoseek.co.jp/MnStock/#{@code}/slast/?sy=#{term[0][0]}&sm=#{term[0][1]}&sd=#{term[0][2]}&ey=#{term[1][0]}&em=#{term[1][1]}&ed=#{term[1][1]}&k=#{method}&st=#{start_page}" doc = Hpricot(open(url)) price_history = [] (doc/"table.ruled"/:tbody/:tr).each do |elem| begin price_history << [elem.at(:th).inner_text.toutf8, elem.at("td.emph").inner_text.toutf8] rescue Exception => e price_history << [elem.at(:th).inner_text.toutf8, nil] p e end end price_history rescue Exception => e puts e ensure end end
private def main_data(code) begin url = "http://money.www.infoseek.co.jp/MnStock/#{code}/sresult/" data =Hpricot(open(url)) (data/"h3#description").each do |elem| begin @name = elem.at("span#dname").inner_text.toutf8 @category = elem.at("span#dname").next_sibling.inner_text.gsub(/\s|\?/,"").toutf8 rescue Exception => e
end end @data = [] (data/"table.ruled").each do |table| begin @data << table.inner_text.toutf8.to_a.reject{ |item| item == "\n" }.each { |item| item.delete!("\n")} @price_data, @credit_data, @company_data, *@value_data = *@data rescue Exception => e
end end rescue Exception => e puts e end end
end if __FILE__ == $0 stocks = ['2678.t', '3382.t', '4659.j', '7974.t', '8227.t', '9064.t', '9983.t'] term = [[2005,1,1],[2008,6,30]] start_page = 0 method = 'm'
stocks.each do |stock| stk = Stock.new(stock) puts stk.name puts stk.category p stk.value_data p stk.price_history(term, method, start_page) end end |