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
trap("SIGINT") { exit! } | |
total_width = `stty size`.scan(/\d+/)[1].to_i # terminal width | |
snowflakes = {} | |
puts "\033[2J"; # clearing output | |
loop do | |
snowflakes[rand(total_width)] = 0 |
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
en: | |
errors: | |
messages: | |
http_unauthorized: 'Authentication required' | |
http_not_found: 'Not found' | |
http_bad_request: 'Incorrect or incomplete input' | |
http_service_unavailable: 'Service unavailable' | |
http_forbidden: 'Forbidden' | |
http_unprocessable_entity: 'Unprocessable Entity' | |
resource_not_found: 'Resource not found' |
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
# Workflow: | |
# | |
# 1- if the path points to a directory | |
# 1.1- if the directory isn't in the exclusion list then: count LOC | |
# 1.2- else: prune directory | |
# 2- else | |
# 1.1- if the file extension is whitelisted then: count LOC | |
# 1.2- else: next | |
require 'find' |
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 hello | |
yield | |
end | |
hello do | |
puts 'hello' | |
redo | |
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
[1,2,3].each do |n| | |
puts "Step #{n}" | |
n += 1 and redo if n < 2 | |
end | |
# produces: | |
# | |
# Step 1 | |
# Step 2 |
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
for i in 1..3 do | |
puts "Iteration #{i}" | |
i += 1 and redo if i == 1 | |
end | |
# produces | |
# | |
# Iteration 1 | |
# Iteration 2 |
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
for i in 1..3 do | |
puts "Iteration #{i}" | |
redo if i == 1 | |
puts 'After redo' | |
end | |
# produces: | |
# |
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
module Patch | |
@@res = refine(Array) {} | |
def self.res; @@res; end | |
end | |
p Patch.res # => #<refinement:Array@Patch> | |
p Patch.res.class # => Module | |
p Patch.res.ancestors # => [#<refinement:Array@Patch>, Array, ...] |
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
module TemporaryPatch | |
refine Hash do | |
def to_s | |
'' | |
end | |
end | |
end | |
my_ebook = { | |
ebook: 'Ruby Object Model', |
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
# lib/core_ext/hash.rb | |
class Hash | |
# monkey-patch to temporarily | |
# disabling the MyLib#print_config output | |
def to_json | |
'' | |
end | |
end |
NewerOlder