snippet

メモ:修正した行は?修正してない行は?

ちょっとした確認依頼にちょっとしたコードで対応できるRubyって素敵 依頼内容を聞きつつコードを書くのが当たり前になりつつある(^^ゞ # files before = File.open("before.csv").lines.to_a after = File.open("after.csv").lines.to_a # conditions match…

メモ:遺物

# coding: CP932 require "tapp" require "inifile" # gem install inifile #require "yaml" require "json" require "xmlsimple" # gem install xml-simple def to_json(hash) hash.to_json.encode(__ENCODING__) end def to_xml(hash) XmlSimple.xml_out(h…

メモ:ダメだ(>_<)

# coding: CP932 # 生成パターン PATTERN = { SEQ: -> size, n {1.upto(1.0/0).take(n).map{|i| "%0#{size}d"%i}}.curry, HIRA: -> size, n {('ぁ'..'ん').cycle.take(size * n).each_cons(size).map(&:join)}.curry, KATA: -> size, n {(('ァ'..'ン').to_a+…

メモ:固定長開始位置

DATAファイルオブジェクト ps_data.rb DATA.lines.map(&:chomp).tap{|sizes| puts sizes.inject([1]){|poses, size| poses << poses.last + size.to_i}.zip(sizes) .map{|(pos, size)| "#{pos}\t#{size}"} } __END__ 21 1 6 1 4 1 16 1 20 1 2 1 69 1 26 1 1…

メモ:なるほど〜

Ruby1.8 cache = { 0 => 0, 1 => 1 } fib = lambda {_fib_ = lambda {|n| cache[n] ||= _fib_[n-2] + _fib_[n-1]}}.call puts (1..20).map(&fib).join(", ") Ruby1.9 cache = { 0 => 0, 1 => 1} fib = -> { _fib_ = -> n { cache[n] ||= _fib_[n-2] + _fib_[…