This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ time curl -Lso - http://bit.ly/ye8vZA | zcat | ruby -rtext -e 'w=ARGF.read.split(/\n/);p %w(インターネト プログラミングル 東強都 任人堂 東京特許許許可局 マロオブラザーズ イーサネッット コソトローラ).map{|i|w.sort_by{|j|Text::Levenshtein.distance(i,j)}[0]}' | |
["インターネット", "プログラミング", "東都", "任天堂", "東京特許許可局", "マリオブラザーズ", "イーサネット", "コントローラ"] | |
real 14m13.030s | |
user 13m28.858s | |
sys 0m5.232s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FactoryGirl::TestHelper | |
include ActionDispatch::TestProcess | |
def self.fixture_file_upload(*args) | |
self.new.fixture_file_upload(*args) | |
end | |
def self.fixture_path | |
File.join(File.dirname(__FILE__) + '/fixtures/') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'find' | |
require 'fileutils' | |
dir = ARGV.shift | |
Find.find(dir) do |f| | |
if File.file?(f) and /20111123.*\.xls$/ =~ f | |
FileUtils.mv(f, f.sub(/20111123/, '20111124'), { :noop => false, :verbose => true }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# まず dry run | |
$ find . -name thumnail.png | ruby -rfileutils -ne '$_.chomp!; FileUtils.mv($_, $_.sub(/thum/, "thumb"), {:noop => true, :verbose => true})' | |
# 本当に実行 | |
$ find . -name thumnail.png | ruby -rfileutils -ne '$_.chomp!; FileUtils.mv($_, $_.sub(/thum/, "thumb"), {:noop => false, :verbose => false})' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ irb | |
ruby-1.8.7-p352 :001 > str = 'a' | |
=> "a" | |
ruby-1.8.7-p352 :002 > str + 'b' | |
=> "ab" | |
ruby-1.8.7-p352 :003 > p str | |
"a" | |
=> nil | |
ruby-1.8.7-p352 :004 > class String | |
ruby-1.8.7-p352 :005?> def +(other) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ irb-ruby-1.9.2-p290 | |
ruby-1.9.2-p290 :001 > RUBY_VERSION | |
=> "1.9.2" | |
ruby-1.9.2-p290 :002 > File.read('test.png').encoding | |
=> #<Encoding:UTF-8> | |
ruby-1.9.2-p290 :003 > image = File.open('test.png', 'r:ascii-8bit'){|f| f.read} | |
<snip> | |
ruby-1.9.2-p290 :004 > image.encoding | |
=> #<Encoding:ASCII-8BIT> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ file test.png | |
test.png: PNG image data, 22 x 13, 16-bit grayscale, non-interlaced | |
$ md5sum test.png | |
c6db60c696981f908324d3365e0836c0 test.png | |
# base64 encoding with ruby 1.8.7 | |
$ irb-ruby-1.8.7-p334 | |
ruby-1.8.7-p334 :001 > RUBY_VERSION | |
=> "1.8.7" | |
ruby-1.8.7-p334 :002 > b64 = [File.read('test.png')].pack('m') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
Person = Struct.new(:name, :age) | |
jo = Person.new("Jo", 15) | |
meg = Person.new("Meg", 16) | |
beth = Person.new("Beth", 10) | |
amy = Person.new("Amy", 7) | |
sisters = [jo, meg, beth, amy] | |
sisters.each{|person| puts person.name } | |
#=> Jo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: ruby-1.9.2-p290/tool/rbinstall.rb | |
=================================================================== | |
--- ruby-1.9.2-p290.orig/tool/rbinstall.rb | |
+++ ruby-1.9.2-p290/tool/rbinstall.rb | |
@@ -491,38 +491,6 @@ | |
end | |
end | |
-install?(:ext, :comm, :gem) do | |
- directories = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby19 | |
# -*- coding: utf-8 -*- | |
require 'mongo' | |
connection = Mongo::Connection.new | |
db = connection.db('apache-log') | |
logs = db.collection('log') | |
map =<<'_FUNC_' |
NewerOlder