-
1.8.7 - Retired since 2013-06-30
-
1.9.3 - Retired since 2015-02-23 - No bug fix, nor even security ones will be backported then
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/env ruby | |
# If no local variable is found, | |
# it begins the method lookup that ends calling | |
# the method_missing chain until the last one raises the error | |
begin | |
p undefined_name if true | |
rescue | |
puts "Raised an error" |
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/env ruby | |
#coding: utf-8 | |
def del_first_three_original_1(a) | |
num_to_del = a.find { |e| a.count(e) >= 3 } | |
return a if num_to_del.nil? | |
3.times do | |
ind = a.index { |e| e == num_to_del } | |
a.delete_at(ind) | |
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
file = File.open "acao_e_reacao_utf16_le.txt" | |
=> #<File:acao_e_reacao_utf16_le.txt> | |
file.methods.grep /enc/ | |
=> [:external_encoding, :internal_encoding, :set_encoding] | |
file.external_encoding | |
=> #<Encoding:UTF-8> | |
file.internal_encoding |
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
#coding: utf-8 | |
# This will remove old Readline if it's already defined | |
require 'rb-readline' | |
# This will load RbReadline for real | |
require 'rbreadline' | |
# This will load Readline that relies on RbReadline | |
require 'readline' |
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
require 'benchmark' | |
n = 100_000 | |
ar = [4,5,6,4,5,6,6,7] | |
Benchmark.bm(15) do |b| | |
b.report("Ralph Shneiver:"){ n.times { result = Hash.new(0); ar.each { |x| result[x] += 1 }; result} } | |
b.report("Sigurd:") { n.times { ar.inject(Hash.new(0)) {|res, x| res[x] += 1; res } } } | |
b.report("Keinich #1") { n.times { Hash[ar.group_by{|n|n}.map{|k,v|[k, v.size]}] } } | |
b.report("Keinich #2") { n.times { Hash.new(0).tap{|h|ar.each{|n|h[n] += 1}} } } | |
b.report("Magnus Holm:") { n.times { ar.each_with_object(Hash.new(0)) { |x, res| res[x] += 1 } } } |
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/env ruby | |
regexp = /^([A-Z]{1,4})([0-9]{1,4})$/ | |
text_phrases = | |
[ "ABCD1234", | |
"ABCDE1234", | |
"ABCD12345", | |
"ABCDE12345"] |
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
def append_data_to_daily_files | |
Dir.entries('A').each do |file| | |
next unless file.match(/today/i) | |
File.open(File.join("A",file), 'a') do |file| | |
file.puts("hello") | |
end | |
end | |
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
require 'psych' | |
class ScalarHandler < Psych::Handler | |
def parser=(parser) | |
@parser=parser | |
end | |
def mark | |
@parser.mark |
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/env ruby | |
def the_main_script | |
# Your main script | |
# Do whatever here | |
x = rand(3) | |
puts "x = #{x}" | |
puts "and 10/#{x} = #{10/x}" # When x==0 ZeroDivisionError | |
end |
OlderNewer