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 DiCaprio | |
include Celluloid | |
def do_a_thing | |
puts "starting" | |
`sleep 1` | |
puts "finished" | |
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 TrapLoop | |
trap('TERM') { stop! } | |
trap('INT') { stop! } | |
trap('SIGTERM') { stop! } | |
def self.stop! | |
@loop = false | |
end | |
def self.safe_exit_point! |
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
ERROR: no command given | |
Usage: test_worker <command> <options> -- <application options> | |
* where <command> is one of: | |
start start an instance of the application | |
stop stop all instances of the application | |
restart stop all instances and restart them afterwards | |
run start the application and stay on top | |
zap set the application to a stopped state |
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 SimpleViz | |
def initialize(app, &lookup) | |
@app = app | |
end | |
def call(env) | |
puts caller | |
request = Rack::Request.new(env) | |
puts "-> #{request.request_method.upcase} (#{request.url})" | |
status, headers, body = @app.call(env) | |
puts "<--#{status}-- #{body.size}" |
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
DataMapper.repository(@repository).adapter.extend(SQL::Mysql) | |
DataMapper.repository(@repository).adapter.recreate_database |
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 Worker | |
include Celluloid | |
def work(x) | |
sleep 0.2; puts x*x | |
end | |
end | |
worker_pool = Worker.pool(size: 10) | |
(0..99).to_a.each{|x| worker_pool.async.work x } | |
sleep 2 #how do I wait the right amount of time before terminating? |
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 BlockRefinement | |
def self.refines(*classes_refined) | |
@classes_refined = classes_refined | |
end | |
def self.refines_method(method_refined, &new_method) | |
@classes_refined.each do |class_refined| | |
old_method = class_refined.instance_method(method_refined) | |
@reverts ||= [] |
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 BlockRefinement | |
def self.refines(*classes_refined) | |
@classes_refined = classes_refined | |
end | |
def self.refines_method(method_refined, &new_method) | |
@classes_refined.each do |class_refined| | |
old_method = class_refined.instance_method(method_refined) | |
@reverts ||= [] |
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 'rubygems' | |
require 'nokogiri' | |
str = "<select id=\"cluster_configuration_data_snapshot_id\" name=\"cluster_configuration[data_snapshot_id]\"></select>" | |
#This one fails | |
failing = Proc.new do | |
innards = "<option data-size=\"15\" value=\"\" volume_size=\"\">New volume</option>\n<option class=\"time\" data-html-suffix=\" (snap-f2e4f551) (Application Master) [64-bit]\" data-size=\"15\" datetime=\"2013-06-20T20:29:32+00:00\" value=\"8\" volume_id=\"14\" volume_size=\"15\" selected>\nThu Jun 20 20:29:32 2013 (snap-f2e4f551) (Application Master) [64-bit]\n</option>" | |
x = Nokogiri::XML::Element.new('select', Nokogiri::XML(str)) | |
x.inner_html = innards |
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
git remote add upstream https://github.com/resque/resque.git | |
git fetch upstream | |
git checkout master | |
git merge upstream/master | |
git push origin master |