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 / rspec_hepler.rb
Created April 14, 2014 01:21
Capybara auto-saving screenshots on test failures
RSpec.configure do |config|
config.after(:each) do
if example.exception && example.metadata[:js]
meta = example.metadata
filename = File.basename(meta[:file_path])
line_number = meta[:line_number]
screenshot_name = "screenshot-#{filename}-#{line_number}.png"
screenshot_path = "#{Rails.root.join("tmp")}/#{screenshot_name}"
page.save_screenshot(screenshot_path)
@osulyanov
osulyanov / gist:27989db9bb6255ff86fe
Created March 10, 2015 09:43
Bootstrap menu dropdown on hover
// outside the scope of the jQuery plugin to
// keep track of all dropdowns
var $allDropdowns = $();
// if instantlyCloseOthers is true, then it will instantly
// shut other nav items when a new one is hovered over
$.fn.dropdownHover = function(options) {
// the element we really care about
// is the dropdown-toggle's parent
@osulyanov
osulyanov / image_uploader.rb
Last active September 11, 2015 08:30
Generate random file name and save old saved file names (CarrierWave FTP)
def filename
if original_filename
if model && model.read_attribute(mounted_as).present?
model.read_attribute(mounted_as)
else
"#{SecureRandom.hex}.#{File.extname(file.filename)}"
end
end
end
@osulyanov
osulyanov / rspec_model_testing_template.rb
Created November 14, 2015 13:28 — forked from PWSdelta/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
#!/usr/bin/env ruby
require 'octokit'
project = ARGV[0]
if project.nil?
puts 'project is empty'
abort
end
client = Octokit::Client.new(:access_token => "")
# Create repo
class ApplicationMailer < ActionMailer::Base
default from: Setting.first.email_from
add_template_helper(EmailHelper)
layout 'mailer'
end
@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"
@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 / 01_readme.md
Last active December 3, 2017 04:55 — forked from palkan/01_readme.md
Docker Dev
@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%'