Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar

Vladimir Dementyev palkan

View GitHub Profile
@palkan
palkan / aggregate_failures.rb
Created March 28, 2017 16:54
Rubocop: RSpec/AggregateFailures
require 'rubocop/rspec/language'
module RuboCop
module Cop
module RSpec
class AggregateFailures < RuboCop::Cop::Cop
GROUP_BLOCKS = RuboCop::RSpec::Language::ExampleGroups::ALL
EXAMPLE_BLOCKS = RuboCop::RSpec::Language::Examples::ALL
def on_block(node)
@palkan
palkan / factory_default.rb
Created March 28, 2017 13:18
FactoryDefault: re-use associated objects in factories
module FactoryDefault
module CreateDefaultMethod
def create_default(name, *args, &block)
res = create(name, *args, &block)
FactoryDefault.register(name, res)
res
end
end
module RunnerExt
@palkan
palkan / Gemfile
Last active April 27, 2024 02:02
FactoryProf: profiler for your FactoryGirl
# if you want to render flamegraphs
gem "stackprof", require: false # required by flamegraph
gem "flamegraph", require: false
@palkan
palkan / factory_doctor.rb
Created March 27, 2017 15:42
FactoryDoc: detect useless data generation in tests
module FactoryGirl
module Doctor
module FloatDuration
refine Float do
def duration
t = self
format("%02d:%02d.%03d", t / 60, t % 60, t.modulo(1) * 1000)
end
end
end
@palkan
palkan / event_profiler.rb
Last active April 3, 2017 18:28
RSpec Events Profiler
module RSpec
class EventProfiler # :nodoc:
# Add #duration method to floats
module FloatDuration
refine Float do
def duration
t = self
format("%02d:%02d.%03d", t / 60, t % 60, t.modulo(1) * 1000)
end
end
@palkan
palkan / rspec-hell.rb
Last active April 18, 2017 17:59
RSpec Hell: run examples concurrently (using threads)
module RSpecHell
def run_examples(reporter)
return super unless metadata[:hell] && !(metadata[:parent_example_group] && metadata[:parent_example_group].key?(:hell))
pool_size = ENV['HELL'].to_i
q = Queue.new
ordering_strategy.order(descendant_filtered_examples).each { |ex| q << ex }
workers = []
results = []
@palkan
palkan / active_record_one_love.rb
Created March 7, 2017 09:28
ActiveRecord OneLove
module ActiveRecord
# Share connection between threads to make it possible to wrap system tests in a transaction.
# Also synchonize queries to avoid concurrent writes/reads.
#
# For PostgreSQL adapter.
module OneLove
class << self
attr_reader :connection
def connection=(conn)
@palkan
palkan / Gemfile
Last active April 25, 2024 14:23
RSpec profiling with RubyProf and StackProf
gem 'stackprof', require: false
gem 'ruby-prof', require: false
@palkan
palkan / post.md
Created December 7, 2016 16:41
AnyCable post

title: 'AnyCable:the Action Cable Power-Up' category: Back-end date: 2016-12-17 description: 'This article tells the story of the AnyCable project which aims to increase Action Cable performance and functionality.' draft: true authors:

name: 'Vladimir Dementyev'

about: 'Back-end Developer at Evil Martians'

@palkan
palkan / docker-clean.sh
Last active November 29, 2016 12:41
Clean Docker Files
#!/bin/bash
# remove exited one-off containers:
docker ps --filter status=dead --filter status=exited -a | grep "_run" | awk '{ print $1 }' | xargs -I@ docker rm -v @
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -I@ docker rmi @
# remove unused volumes
docker volume ls -qf dangling=true | xargs -I@ docker volume rm @