Skip to content

Instantly share code, notes, and snippets.

@DmytroVasin
DmytroVasin / MyHash
Last active February 20, 2017 16:44
require 'test/unit'
require 'benchmark'
# For Ruby 2.3
# user system total real
# Ruby Hash 0.030000 0.000000 0.030000 ( 0.033555)
# My Hash 0.360000 0.000000 0.360000 ( 0.367558)
# For Ruby 2.4
# user system total real
@DmytroVasin
DmytroVasin / Assets be_undefined_in_js (Rspec)
Last active February 28, 2017 19:07
Extend Rspec to include additional matcher.
describe "Assets", type: :feature, js: true do
describe "application.js" do
it "does not include page-specific content" do
visit root_path
expect("d3").to be_undefined_in_js
expect("moment").to be_undefined_in_js
end
end
@DmytroVasin
DmytroVasin / .railsrc
Created April 8, 2017 18:38
number of “flags” which will provide some initial customizations for the new project
--database=postgresql
--skip-action-cable
--skip-spring
--skip-coffee
--skip-turbolinks
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"
class TripReservationsController < ApplicationController
def create
reservation = TripReservation.new(params[:trip_reservation])
trip = Trip.find_by_id(reservation.trip_id)
agency = trip.agency
payment_adapter = PaymentAdapter.new(buyer: current_user)
unless current_user.can_book_from?(agency)
redirect_to trip_reservations_page, notice: TripReservationNotice.new(:agency_rejection)
export BUNDLER_EDITOR="/usr/local/bin/subl"
export EDITOR="/usr/local/bin/subl"
### Added by the Heroku Toolbelt
export PATH="$HOME/.rvm/bin:$PATH"
export PATH="/usr/local/heroku/bin:$PATH"
export PATH="/usr/local/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
### Yarn:
export PATH="$HOME/.config/yarn/global/node_modules/.bin:$PATH"
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
@DmytroVasin
DmytroVasin / image_uploader.rb
Last active October 21, 2017 12:20
Carrierwave bug with version inheritance. ( Part 1 )
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"image/#{model.id}"
end
version :small do
@DmytroVasin
DmytroVasin / purchased_image_uploader.rb
Last active October 21, 2017 12:21
Carrierwave bug with version inheritance. ( Part 2 )
class PurchasedImageUploader < ImageUploader
def store_dir
"purchased_image/#{model.id}"
end
end
@DmytroVasin
DmytroVasin / purchased_image_uploader.rb
Created October 21, 2017 13:03
Carrierwave bug with version inheritance. ( Part 3 )
class PurchasedImageUploader < ImageUploader
def store_dir
"purchased_image/#{model.id}"
end
version :small do
def store_dir
"purchased_image/#{model.id}"
end