Skip to content

Instantly share code, notes, and snippets.

View ohnishiakira's full-sized avatar

Akira Ohnishi ohnishiakira

View GitHub Profile
for cmd in $(ruby -e 'print "irb".split(//).permutation(3).map(&:join).join(" ")')
do
alias $cmd="pry"
done
#!/usr/bin/env ruby
# coding: utf-8
require "forwardable"
require "csv"
require "MeCab"
class Mecab
def self.wakati
#!/usr/bin/env ruby
# coding: utf-8
class Hoge
FUGA = "fuga"
end
hash = {hoge: Hoge}
p hash[:hoge]::FUGA #=> "fuga"
#!/usr/bin/env ruby
# coding: utf-8
hash = [
{hoge: {fuga: 3}},
{hoge: {homu: 5}},
{fuga: {hoge: 4}},
{fuga: {pero: 6}}
]
#!/usr/bin/env ruby
# coding: utf-8
require "date"
def default_time(now=DateTime.now)
@default_time ||= now
end
module ShowDefaultTime
#!/usr/bin/env ruby
# coding: utf-8
require "csv"
rows = [
[nil, "ほげ"],
["", "ほげ"]
]
#!/usr/bin/env ruby
# coding: utf-8
require 'pp'
require 'date'
def each_by_time(a, b)
min_count = ((b - a) * 24*60).to_i + 1
min_count.times.map{|t|
@ohnishiakira
ohnishiakira / gist:6821832
Last active December 24, 2015 15:39
シンタックスエラーになる(MacOSX10.7.5、Ruby1.9.3-p448)
#!/usr/bin/env ruby
# coding: utf-8
flag = true
array = [1,2,3]
# array.include?(3) だと動く
if flag && array.include? 3
p 'ok'
end
#!/usr/bin/env ruby
# coding: utf-8
def levenshtein(a, b)
(0..a.size).inject([[*0..b.size+1]]){|d, i|
d << (0..b.size).inject([i+1]){|_d, j|
_d << [
d[i][j+1] + 1,
_d[j] + 1,
d[i][j] + (a[i]==b[j] ?0:1)
@ohnishiakira
ohnishiakira / normalize_voiced_sound_mark.rb
Created June 25, 2013 13:46
濁点が分かれてる文字を正規化(?)する
"た゛くてんか゛ふ゛んりされてるもし゛".gsub("\u309B", "\u3099").gsub("\u309C", "\u309A").encode("UTF-8", "UTF-8-MAC")
# => "だくてんがぶんりされてるもじ"