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
queue = LimitedWorkQueue(EventMachine, 2) | |
messages.each do |message| | |
queue.add do | |
message.send # no more than 2 of these will run at the same time | |
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
responses = | |
ExceptionalSynchrony::ParallelSync.parallel(EventMachine) do |parallel| | |
messages.each do |message| | |
parallel.add { message.send } | |
end | |
end | |
responses.each { ... } |
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 Secrets | |
def initialize(secrets_path) | |
@hash = YAML.load_file(secrets_path) | |
end | |
def [](key) | |
@hash[key] | |
end | |
def set_instance |
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 'mysql2' | |
module Invoca | |
module Mysql2AdapterKillOnTimeout | |
def kill(thread_id) | |
@connection.query("KILL #{thread_id}") | |
end | |
def execute(sql, name = nil) |
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 ParseFigLeaf | |
def parse(*args) | |
arg0 = args.first | |
arg0.is_a?(String) && arg0 =~ /\A\d\d[-\/]\d\d[-\/]\d\d/ and raise "Ambiguous parse format in #{arg0.inspect}" | |
super | |
end | |
end | |
class << Date | |
prepend ParseFigLeaf |
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
result = | |
retry_on_exception(Timeout::Error, total_tries: 2) do | |
http_fe.post(...) | |
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
tiles = {} | |
STDIN.readlines.map.with_index do |line, y| | |
x = 0 | |
line.chomp.split(".").each do |segment| | |
unless segment.empty? | |
tile = [x, segment.size, segment[0]] | |
if value = tiles[tile] | |
tiles[tile] = [value.first, value.last + 1] | |
else |
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 User < ApplicationModel | |
fields :null=>false do | |
first_name :string | |
last_name :string | |
time_zone :string | |
encrypted_password :binary, :limit => 255 | |
last_login_at :datetime, :null=>true | |
tos_agreed_date :datetime, :null=>true | |
registered_IP_address :string, :null=>true | |
contact_country_code :string, :limit => 3, :default => "" |
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 User < ActiveRecord::Base | |
attr_default :first_name, 'First' | |
attr_default :last_name, 'Last' | |
attr_default :name_addr, lambda { "#{full_name} <#{email}>" } | |
attr_default :email, lambda { organization.default_email } | |
def full_name | |
[first_name, middle_name, last_name].select { |name| !name.blank? } * ' ' | |
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 User < ActiveRecord::Base | |
fields do | |
first_name :string, :ruby_default => 'First' | |
last_name :string :ruby_default => 'Last', :null => false, :default => '' | |
name_addr :string, :ruby_default => lambda { "#{full_name} <#{email}>" } | |
email :string :ruby_default => lambda { organization.default_email } | |
level :enum, :limit => [:Basic, :Admin, :Super], :default => :Basic, :null => false | |
end | |
def full_name |
OlderNewer