Skip to content

Instantly share code, notes, and snippets.

View igkuz's full-sized avatar

Igor Kuznetsov igkuz

  • Antalya, Turkey
View GitHub Profile
igkuz / start.rb
Created March 12, 2019 16:06
Starting point to create RabbitMQ exchanges and queues with ruby
View start.rb
#!/usr/bin/env ruby
# encoding utf-8
require 'bunny'
STDOUT.sync = true
conn = 'rmq', user: 'guest', pass: 'guest')
igkuz / consumer.rb
Created March 12, 2019 15:59
Ruby consumer for RabbitMQ queue with rate-limiting based on Redis
View consumer.rb
#!/usr/bin/env ruby
# encoding utf-8
require 'bunny'
require 'logger'
require 'redis'
logger =
STDOUT.sync = true
igkuz / publisher.rb
Created March 12, 2019 15:58
Ruby publisher for RabbitMQ queue with bunny gem
View publisher.rb
#!/usr/bin/env ruby
# encoding utf-8
require 'bunny'
require 'json'
STDOUT.sync = true
conn = 'rmq', user: 'guest', pass: 'guest')
igkuz / Gemfile
Last active March 12, 2019 15:08
Gemfile for bunny
View Gemfile
source ''
gem 'bunny'
gem 'redis'
igkuz / factories.rb
Created March 9, 2019 16:21
Define factories with rom-factory
View factories.rb
let(:factories) do
ROM::Factory.configure do |config|
config.rom = MAIN_CONTAINER
before do
factories.define(:post) do |f|
f.url { fake(:internet, :url, '') }
f.se_post false
igkuz / create_company.rb
Created March 9, 2019 14:18
ROM Commands for Post and Company
View create_company.rb
class CreateCompany < ROM::Commands::Create[:sql]
relation :companies
register_as :create
result :one
use :timestamps
timestamp :created_at, :updated_at
igkuz / companies.rb
Created March 9, 2019 13:59
ROM Relations for Post & Company
View companies.rb
class Companies < ROM::Relation[:sql]
schema(:companies, infer: true) do
associations do
has_many :posts
View 20190309132643_create_companies.rb
ROM::SQL.migration do
change do
create_table :companies do
primary_key :id
column :name, String, null: false
column :domain, String, null: false
column :state, String, null: false, default: 'running'
column :created_at, DateTime
column :updated_at, DateTime
igkuz / Rakefile
Created March 9, 2019 13:18
Rakefile for sample ROM app with db:setup
View Rakefile
require_relative 'boot'
require 'rom/sql/rake_task'
namespace :db do
task :setup do
configuration =, "mysql2:///#{CONFIG['db']['name']}", CONFIG['db'])
ROM::SQL::RakeSupport.env = configuration
View console
#!/usr/bin/env ruby
require_relative 'boot'
db_config = {
name: 'rom_app_development',
host: 'db',
user: 'root',
password: '',
port: 3306,
encoding: 'utf8mb4'