Skip to content

Instantly share code, notes, and snippets.

View havenwood's full-sized avatar
:octocat:

Shannon Skipper havenwood

:octocat:
  • Ashland, Oregon
  • 01:50 (UTC -07:00)
View GitHub Profile
@havenwood
havenwood / hello-world.rb
Created February 27, 2012 21:12
Hello world with unit test
require 'minitest/autorun'
require 'minitest/pride'
module HelloWorld
def self.hello_world
p 'hello world'
end
end
class TestHelloWorld < MiniTest::Unit::TestCase
@havenwood
havenwood / to_regex.rb
Created March 1, 2012 17:47
Concept for tool to convert English to the equivalent Regex
# 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 "!"
@havenwood
havenwood / bang.rb
Created March 6, 2012 03:47
Celluloid Timer Countdown Example
require 'celluloid'
class Bomb
include Celluloid
def initialize countdown = 10
@timer = after(countdown) { puts "BANG!!" }
end
def reset_clock
@havenwood
havenwood / requires.rb
Created April 8, 2012 19:50
require multiple gems on one line
# 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
@havenwood
havenwood / thread.rb
Created April 25, 2012 22:44
Threading to Wait
def handler()
@handlerpid = Thread.new do
Signal.trap("HUP") do
warn "Force closing \"#{@server}\" handler"
exit
end
until @socket.eof? do
msg = @socket.gets
@havenwood
havenwood / persist.rb
Created May 21, 2012 20:33
Persist.db Alpha
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
@havenwood
havenwood / d3status.rb
Created June 7, 2012 17:50
D3 US Server Status from IRB/Pry
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
@havenwood
havenwood / concurrent_array.rb
Created June 11, 2012 21:51
concurrent array making with Celluloid
require 'celluloid'
class ArrayMaker
include Celluloid
attr_reader :content
def initialize
@content = []
end
@havenwood
havenwood / stringify.rb
Created June 11, 2012 22:30
#stringify_keys! as from active_support
class Hash
def stringify_keys!
keys.each { |k| self[k.to_s] = delete k }
self
end
end
@havenwood
havenwood / required_gems.rb
Last active November 27, 2015 05:28
Check Which Gems are Required
def required_gems
$LOAD_PATH.grep(/\/lib\z/).map do |path|
path.match(/([^\/]+)-([^-]+)\/lib\z/).captures
end.to_h
end