Skip to content

Instantly share code, notes, and snippets.

View semenyukdmitry's full-sized avatar

Dmitry Semenyuk semenyukdmitry

View GitHub Profile
@semenyukdmitry
semenyukdmitry / Gemfile
Created June 26, 2020 08:37 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@semenyukdmitry
semenyukdmitry / hashquiz.rb
Created August 15, 2018 13:31 — forked from potatosalad/hashquiz.rb
Ruby quiz for convert hash "dot paths" into actual hash hierarchy.
#require 'rubygems'
require 'pp'
#require 'ap' # Awesome Print
class Object
# expects [ [ symbol, *args ], ... ]
def recursive_send(*args)
args.inject(self) { |obj, m| obj.send(m.shift, *m) }
end
end
module TestState
InvalidStateError = Class.new(RuntimeError)
def get_state stately
Object.const_get("TestState::#{stately.state}").new stately
rescue NameError
raise InvalidStateError, "Invalid State '#{stately.state}'"
end
ACTIONS = [:start, :stop]
# Ruby Thread Pool
# ================
# A thread pool is useful when you wish to do some work in a thread, but do
# not know how much work you will be doing in advance. Spawning one thread
# for each task is potentially expensive, as threads are not free.
#
# In this case, it might be more beneficial to start a predefined set of
# threads and then hand off work to them as it becomes available. This is
# the pure essence of what a thread pool is: an array of threads, all just
# waiting to do some work for you!