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 / ru.yml
Created April 8, 2014 07:09
Translations for nested attributes
ru:
activerecord:
theme/posts:
text: Содержание # theme[posts][text]
@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 SabretWoW/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:
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
mkdir ~/bin
export PATH=~/bin:$PATH
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
export EDITOR='subl -w'
git config --global core.editor "subl -n -w"
@osulyanov
osulyanov / copy_paperclip_data.rb
Created January 28, 2013 06:45
Move existing Paperclip attachments to a new path Case in: lib/tasks/copy_paperclip_data.rb And run: rake copy_paperclip_data
desc "Copy paperclip data"
task :copy_paperclip_data => :environment do
@users = User.find :all
@users.each do |user|
unless user.image_file_name.blank?
filename = Rails.root.join('public', 'system', 'images', user.id.to_s, 'original', user.image_file_name)
if File.exists? filename
image = File.new filename
user.image = image
@osulyanov
osulyanov / application.css
Created February 7, 2013 10:41
Custom file input
.file_upload {
position: relative;
overflow: hidden;
float: left;
margin-right: 4px;
}
.file_upload input {
position: absolute;
top: 0;
right: 0;
@osulyanov
osulyanov / gist:4761923
Created February 12, 2013 12:12 — forked from moiristo/gist:1245170
Rails3 way to redirect non-www domain to www domain
# Rails3 way to redirect non-www domain to www domain
# Single domain redirect
'example.com'.tap do |host|
constraints(:host => host) do
match '/(*path)', :to => redirect { |params, request| Addressable::URI.escape request.url.sub(host, "www.#{host}") }
end
end