Skip to content

Instantly share code, notes, and snippets.

View osulyanov's full-sized avatar
🎯
Focusing

Oleg osulyanov

🎯
Focusing
  • Passion.io
View GitHub Profile
@osulyanov
osulyanov / order.rb
Last active September 19, 2019 07:57
Controller for refactoring
# Service class emulates Rails ActiveRecord
class ActiveRecord
def initialize(params={}); end
end
# Order model
class Order < ActiveRecord
attr_accessor :country_code,
:first_name,
:last_name,
@osulyanov
osulyanov / clear-sidekiq-jobs.sh
Created February 20, 2018 11:38 — forked from wbotelhos/clear-sidekiq-jobs.sh
Clear Sidekiq Jobs
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
# 3. Clear 'Processed' and 'Failed' jobs
@osulyanov
osulyanov / config.yml
Last active November 30, 2022 23:58
Circle CI workflows config to test and deploy Ruby on Rails application with PostgreSQL database. Test with Rspec, precompile assets then deploy with Capistrano.
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/ruby:2.4.1-node-browsers
environment:
@osulyanov
osulyanov / task_hooks.md
Created December 5, 2017 13:15 — forked from Earendil95/task_hooks.md
Git hooks for automatic reference issues in commit

Description

This hooks will remind you to reference task in your commit, and remember your task ref for branch. Your commit messages will have style "[reference] message"

Usage

  1. Create two files in your repo - e.g. [PROJECT_ROOT]/hooks/prepare-commit-msg.rb and [PROJECT_ROOT]/hooks/post-checkout.rb
  2. Copy to first file (here will assume that this is a [PROJECT_ROOT]/hooks/prepare-commit-msg.rb):
#!/usr/bin/env ruby
@osulyanov
osulyanov / rubocop_pre_commit_hook
Created December 3, 2017 04:57 — forked from mpeteuil/rubocop_pre_commit_hook
Ruby style guide git pre-commit hook using Rubocop as the style guide checker. Only runs on staged ruby files that have been added and/or modified.
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
@osulyanov
osulyanov / postgres_queries_and_commands.sql
Created December 3, 2017 04:57 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@osulyanov
osulyanov / 01_readme.md
Last active December 3, 2017 04:55 — forked from palkan/01_readme.md
Docker Dev
@osulyanov
osulyanov / average_color.rb
Created September 15, 2017 10:09
Get average color of image. In this example `Image` model with `file` file.
after_commit :set_average_color
def set_average_color
return unless self == section.images.first || section.bg_color.blank?
section.update_attribute :bg_color, get_average_color
end
def get_average_color
img = Magick::Image.read(file.path).first
pix = img.scale(1, 1)
@osulyanov
osulyanov / active_admin.rb
Created May 8, 2017 08:58
ActiveAdmin custom menu links
# config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
config.namespace :admin do |admin|
admin.build_menu do |menu|
menu.add :label => "The Application", :url => "/", :priority => 0
menu.add :label => "Sites" do |sites|
sites.add :label => "Google", :url => "http://google.com", :html_options => { :target => :blank }
sites.add :label => "Facebook", :url => "http://facebook.com"
sites.add :label => "Github", :url => "http://github.com"
class ApplicationMailer < ActionMailer::Base
default from: Setting.first.email_from
add_template_helper(EmailHelper)
layout 'mailer'
end