Skip to content

Instantly share code, notes, and snippets.

View hrom512's full-sized avatar

Roman Khrebtov hrom512

View GitHub Profile
module ApplicationHelper
def present(model)
return if model.blank?
klass = "#{model.class}Presenter".constantize
presenter = klass.new(model, self)
yield(presenter) if block_given?
presenter
end
end
@hrom512
hrom512 / postgresql.sh
Last active February 12, 2016 09:20
SSH Tunnels
ssh -fNg -L 5555:localhost:5432 remote_user@remote_host -p123
@hrom512
hrom512 / enum.rb
Created March 9, 2016 20:03
Ruby Enum type
class Enum
attr_reader :name
attr_reader :value
def initialize(name, value)
@name = name
@value = value
end
def to_i
@hrom512
hrom512 / projects.css
Last active October 27, 2016 08:40
Github custom styles
/* Прокрутка всех столбцов одновременно, отступы, ширина столбца */
.project-columns {
padding-left: 10px;
padding-right: 10px;
}
.project-columns-container {
height: auto;
display: table;
border-spacing: 10px;
margin-top: -10px;
@hrom512
hrom512 / delayed_debug.rb
Created November 6, 2016 16:31 — forked from brainopia/delayed_debug.rb
Non blocking delayed debugger for production
module Developer
extend self
delegate :establish_connection, :clear_all_connections!, :to => ActiveRecord::Base
def delayed_debug(scope)
detach_process do
close_io_objects
establish_connection
setup_process_name
notify_developers
@hrom512
hrom512 / resque.rake
Created March 3, 2017 08:54 — forked from ewherrmann/resque.rake
Collection of Resque related custom rake tasks from around the web
require 'resque/tasks'
namespace :resque do
def del(key)
Resque.redis.keys(key).each { |k| Resque.redis.del(k) }
end
desc "Resque setup according to installation guide"
task :setup => :environment
@hrom512
hrom512 / dependency_injection_example.rb
Last active March 5, 2017 19:19
Dependency Injection example
# Source: https://discuss.dry-rb.org/t/examples-of-how-to-use-dry-container-dry-auto-inject/82/9
require 'dry-container'
require 'dry-auto_inject'
module Api
def self.configure
container.register :main_component, -> { MainComponent.new }
container.register :dependency, -> { Dependency.new }
container.freeze
@hrom512
hrom512 / translations.md
Last active May 29, 2017 11:46
Правила перевода

Информация для переводчиков

1. Спец. символы

Неразрывный пробел: \_

Примеры:

route_info: "Информация о\_рейсе"
title: "Билеты на\_автобус"
@hrom512
hrom512 / migrations_helper.rb
Last active April 4, 2018 08:22
Rails migrations: add column with default to large tables
module MigrationsHelper
# Usage:
# include MigrationsHelper
# disable_ddl_transaction!
#
# def up
# add_column_with_default :articles, :priority, :float, default: 1.0, null: false
# end
#
# def down
@hrom512
hrom512 / vcr.rb
Last active February 12, 2021 14:49
VCR tips
VCR_COMMON_HEADERS = %w[Content-Type Accept Accept-Encoding Authorization].freeze
VCR.configure do |config|
common_headers_proc = ->(request) { request.headers.slice(*VCR_COMMON_HEADERS) }
config.register_request_matcher :common_headers do |request1, request2|
common_headers_proc[request1] == common_headers_proc[request2]
end
# https://github.com/vcr/vcr/blob/master/features/request_matching/README.md
config.default_cassette_options = {