Skip to content

Instantly share code, notes, and snippets.

View developer88's full-sized avatar

Andrey Eremin developer88

View GitHub Profile
@developer88
developer88 / collection_decorator.rb
Created January 16, 2013 12:21
Fix problem with Pagination's Gem for Rails and Draper and Kaminari gem
# This is a dirty hack to fix Draper problem with kaminari
# Put this in app/decorators/collection_decorator.rb
class Draper::CollectionDecorator
delegate :current_page, :total_pages, :limit_value
def total_count
source.total_count
end
@developer88
developer88 / active_admin.rb
Last active March 19, 2016 20:18
This is my gist that show how we can use CanCan with ActiveAdmin and store permissions in database.
# config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
config.current_user_method = :current_user
config.authentication_method = :authenticate_user!
config.before_filter :admin_role_filter
end
# Adding all recource names to Permissions table after ActiveAdmin is loaded
@developer88
developer88 / some_recource.rb
Created February 28, 2013 10:55
Add custom header for has_many form in Active Admin
# in any ActiveAdmin Resource you need in form block add the following code
# change 'translations' with your association name
f.has_many :translations do |translation|
translation.inputs("Caption"){} # Adding caption for languages
translation.inputs(""){} # Spacer
translations.input # add necessary inputs here
end
@developer88
developer88 / in_some_active_admin_resource.rb
Created March 4, 2013 15:43
Ugly hack to display error messages in ActiveAdmin form
if f.object.errors.size > 0
f.inputs I18n.t("active_admin.errors") do
content_tag(:li, f.object.errors.full_messages.join('<br/>').html_safe, class: 'errors_messages')
end
end
@developer88
developer88 / some_active_admin_resource.rb
Created March 5, 2013 13:49
Add custom method to export table as CSV file for ActiveAdmin Resource + scope items from filter + save csv file compatible with Russian Microsoft Office Excel
filter :reception_reception_date, as: :date_range, label: Reception.human_attribute_name(:reception_date_full)
collection_action :download_report, :method => :get do
services = Service.includes(:order, reception: [{medic: :clinic_medics}]).where{ orders.orderable_id != nil } # necessary model
if params[:q] && params[:q][:reception_reception_date_gte].length > 1
services = services.where("receptions.reception_date >= ?", params[:q][:reception_reception_date_gte])
end
if params[:q] && params[:q][:reception_reception_date_lte].length > 1
services = services.where("receptions.reception_date < ?", params[:q][:reception_reception_date_lte])
end
@developer88
developer88 / .bash_profile
Last active December 18, 2015 15:19
.bash_profile for Mac OS X
# Hack for using proxy on MacOS X
export http_proxy="http://LOGIN:PASSWORD@ADDRESS:PORT"
export ftp_proxy="http://LOGIN:PASSWORD@ADDRESS:PORT"
export FTP_PROXY="http://LOGIN:PASSWORD@ADDRESS:PORT"
export HTTP_PROXY="http://LOGIN:PASSWORD@ADDRESS:PORT"
export ALL_PROXY="http://LOGIN:PASSWORD@ADDRESS:PORT"
# Aliases
alias curl="curl -x LOGIN:PASSWORD@ADDRESS:PORT"
alias svn=colorsvn
@developer88
developer88 / csv_export.rb
Last active January 1, 2016 08:59
Export data to Excel in csv format
# For windows only.
#
csv_string = CSV.generate(col_sep: ";", encoding: 'Windows-1251') do |csv|
csv << "Add some data"
end
send_data(csv_string.encode('Windows-1251'), type: 'text/csv; charset=windows-1251; header=present', disposition: "attachment", filename: "file_to_export.csv")
@developer88
developer88 / index.html.slim
Last active August 29, 2015 13:56 — forked from axelav/scrollspy.coffee
SpyOn Directive for AngularJS >= 1.2
#root { scroll-spy data-top-buffer="200" }
div spy="profile_info_part"
| Spy on profile info part and add 'active'class to this div
div
a name="profile_info_part" id="profile_info_part"
@developer88
developer88 / .profile
Last active March 2, 2017 14:24
Some PostgreSQL snippets
alias 'pg_sql_restore'='PGPASSWORD=SOMEPASSWORD psql -cO -U username -d dbname -h localhost -f ' # + set path to backup file
alias 'pg_tar_restore'='PGPASSWORD=SOMEPASSWORD pg_restore -cO -U username -d dbname -h localhost ' # + set path to backup file
@developer88
developer88 / deploy.rb
Last active June 21, 2018 13:05
Deploy phpBB with Mina
require 'mina/bundler'
require 'mina/git'
set :application, "forum"
set :domain, '%SERVERNAME%'
set :deploy_to, "%PATH-TO-APPLICATION%"
set :repository, '%REPOSITORY-URL%.git'
set :branch, 'master'
set :login, "%LOGIN%"