Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Oleg osulyanov

🎯
Focusing
Block or report user

Report or block osulyanov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@osulyanov
osulyanov / order.rb
Last active Sep 19, 2019
Controller for refactoring
View order.rb
# 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,
View clear-sidekiq-jobs.sh
# 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 Nov 7, 2019
Circle CI workflows config to test and deploy Ruby on Rails application with PostgreSQL database. Test with Rspec, precompile assets then deploy with Capistrano.
View config.yml
# 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 Dec 5, 2017 — forked from Earendil95/task_hooks.md
Git hooks for automatic reference issues in commit
View task_hooks.md

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 Dec 3, 2017 — 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.
View rubocop_pre_commit_hook
#!/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
View postgres_queries_and_commands.sql
-- 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 Dec 3, 2017 — forked from palkan/01_readme.md
Docker Dev
View 01_readme.md
@osulyanov
osulyanov / average_color.rb
Created Sep 15, 2017
Get average color of image. In this example `Image` model with `file` file.
View average_color.rb
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
ActiveAdmin custom menu links
View active_admin.rb
# 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"
View application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: Setting.first.email_from
add_template_helper(EmailHelper)
layout 'mailer'
end
You can’t perform that action at this time.