Skip to content

Instantly share code, notes, and snippets.

View nlevchuk's full-sized avatar
🪐

Nikita Levchuk nlevchuk

🪐
View GitHub Profile
@nlevchuk
nlevchuk / shared_folder_centos_virtualbox.txt
Created January 2, 2017 20:37 — forked from larsar/shared_folder_centos_virtualbox.txt
Mount shared folder on CentOS in VirtualBox
# The VirtualBox documentation[1] for how to install guest additions
# for Linux on a virtual host is somewhat messy. So here is what
# I did to make it work.
# Install the packages required
yum update
yum install gcc kernel-devel make bzip2
reboot
if Rails.env.production?
PAYPAL_ACCOUNT = 'production@gmail.com'
else
PAYPAL_ACCOUNT = 'development@gmail.com'
ActiveMerchant::Billing::Base.mode = :test
end
@nlevchuk
nlevchuk / Rails_MockSmtp.rb
Last active January 2, 2016 19:09
rails dev environment and MockSmtp (for catching mails on dev machine) \n MacOS X \n config/environments/development.rb
Example::Application.configure do
....
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {:address => "localhost", :port => 1025, :domain => 'example.com'}
...
end
@nlevchuk
nlevchuk / gist:7738269
Created December 1, 2013 17:48
console sending mail
custom = ::Mail.new(raw_email)
key = Rails.application.config.action_mailer.delivery_method
delivery_method = ActionMailer::Base.delivery_methods.fetch(key)
delivery_settings = ActionMailer::Base.send("#{key}_settings")
custom.delivery_method(delivery_method, delivery_settings)
custom.deliver
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
class Avatar < ActiveRecord::Base
attr_accessor :content_type, :original_filename, :image_data
before_save :decode_base64_image
has_attached_file :image,
PAPERCLIP_CONFIG.merge(
:styles => {
:thumb => '32x32#',
:medium => '64x64#',
require 'rubygems'
require 'rubygems/package'
require 'zlib'
require 'fileutils'
module Util
module Tar
# Creates a tar file in memory recursively
# from the given path.
#
PROMPT='%{$fg_bold[blue]%}$(git_prompt_info) %{$reset_color%}%2~%B%{$fg_bold[red]%} »%b '
RPROMPT='[%*]'
ZSH_THEME_GIT_PROMPT_PREFIX="(%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%b%{$fg_bold[blue]%})%{$reset_color%}"
# download and make Redis
$ wget http://redis.googlecode.com/files/redis-2.6.7.tar.gz
$ sudo tar xzf redis-2.6.7.tar.gz -C /usr/lib/
$ cd /usr/lib/redis-2.6.7
$ sudo make
# create symlinks to the /usr/local/bin
$ sudo ln -s /usr/lib/redis-2.6.7/src/redis-server /usr/local/bin/redis-server
$ sudo ln -s /usr/lib/redis-2.6.7/src/redis-cli /usr/local/bin/redis-cli
class ApplicationController < ActionController::Base
# ...
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: lambda { |exception| render_error 500, exception }
rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: lambda { |exception| render_error 404, exception }
end
private
def render_error(status, exception)