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 'minitest/autorun' | |
require 'minitest/pride' | |
module HelloWorld | |
def self.hello_world | |
p 'hello world' | |
end | |
end | |
class TestHelloWorld < MiniTest::Unit::TestCase |
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
# Morning idea: Ruby tool for translating English to the equivalent Regex, like so: | |
require 'to_regex' | |
English.to_regex do | |
beginning_of_line | |
string "Hi there" | |
whitespace_character one_or_more | |
letter_number_or_underscore 4 | |
string "!" |
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 'celluloid' | |
class Bomb | |
include Celluloid | |
def initialize countdown = 10 | |
@timer = after(countdown) { puts "BANG!!" } | |
end | |
def reset_clock |
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 multiple gems on one line. | |
# | |
# msgs - One or more gem names as Strings. | |
# | |
# Example | |
# | |
# requires 'pry', 'pry-doc', 'gist' | |
# #=> { "pry" => false, "pry-doc" => false, "gist" => true } | |
# | |
# Instead of |
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 handler() | |
@handlerpid = Thread.new do | |
Signal.trap("HUP") do | |
warn "Force closing \"#{@server}\" handler" | |
exit | |
end | |
until @socket.eof? do | |
msg = @socket.gets |
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 'pstore' | |
require 'persist/version' | |
# Public: Implements a DSL around Ruby Standard Library's PStore to facilitate | |
# simple file-persistant storage of Ruby objects in a transactional NoSQL | |
# database. | |
module Persist | |
class << self | |
# Returns the persistant store Object if one has been initialized. | |
attr_reader :store |
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 'nokogiri' | |
require 'open-uri' | |
module D3 | |
def self.status | |
status = Nokogiri::HTML(open 'http://us.battle.net/d3/en/status') | |
status.search('div.status-icon').first.attributes['data-tooltip'].value | |
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 'celluloid' | |
class ArrayMaker | |
include Celluloid | |
attr_reader :content | |
def initialize | |
@content = [] | |
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
class Hash | |
def stringify_keys! | |
keys.each { |k| self[k.to_s] = delete k } | |
self | |
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
def required_gems | |
$LOAD_PATH.grep(/\/lib\z/).map do |path| | |
path.match(/([^\/]+)-([^-]+)\/lib\z/).captures | |
end.to_h | |
end |