Skip to content

Instantly share code, notes, and snippets.

View aishek's full-sized avatar
👨‍💻

Aleksandr Borisov aishek

👨‍💻
  • Tver', Russia
View GitHub Profile
@aishek
aishek / gist:4033090
Created November 7, 2012 17:30
piece of cake to convert crlftolf
task 'crlftolf', '', ->
execFile(
'find'
["#{__dirname}/www"]
(err, stdout, stderr) ->
file_list = stdout.split('\n')
for file in file_list
if file
stats = fs.lstatSync(file)
unless stats.isDirectory()
@aishek
aishek / deploy.rb
Last active December 27, 2015 08:58
Sidekiq Capistrano extension to use different sidekiq_processes on different hosts. Disadvantage of using this extension is sequental only commands execution (no parallel execution support).
require 'sidekiq/capistrano'
load 'config/deploy/extensions/sidekiq' # required to be after require 'sidekiq/capistrano'
set :sidekiq_role, :sidekiq
role :sidekiq, 'server1.com', 'server2.com'
# you may use default syntax – same number of processes at all hosts
# set :sidekiq_processes, 1
# or use hash notation to specify host-dependent number of processes
@aishek
aishek / unauthorized_cross-origin_response_fix.rb
Last active November 7, 2017 17:20
Fixes unauthorized cross-origin response problem for .js templates (problem description in Russian http://habrahabr.ru/post/209618/) in Ruby On Rails 3.2. For Rails 4 just save https://raw2.github.com/rails/rails/4f4fdd643f9d19fbbeeec3ac77674f791c9beffa/actionpack/lib/action_controller/metal/request_forgery_protection.rb to config/initializers/u…
# config/initializers/unauthorized_cross-origin_response_fix.rb
#
# Fixes unauthorized cross-origin response problem for .js templates (problem description in Russian http://habrahabr.ru/post/209618/)
# in Ruby On Rails 3.2, idea and code extracted from https://github.com/rails/rails/blob/4f4fdd643f9d19fbbeeec3ac77674f791c9beffa/actionpack/lib/action_controller/metal/request_forgery_protection.rb
#
# for Rails 4 just save https://raw2.github.com/rails/rails/4f4fdd643f9d19fbbeeec3ac77674f791c9beffa/actionpack/lib/action_controller/metal/request_forgery_protection.rb
# to config/initializers/unauthorized_cross-origin_response_fix.rb
#
# for Rails 4.1 there is https://github.com/rails/rails/pull/13345)
@aishek
aishek / application_controller.rb
Last active August 29, 2015 14:05
Ruby on Rails 4.1 auth concern with six gem
# app/controllers/web/application_controller.rb
class Web::ApplicationController < ApplicationController
include Concerns::Auth
rescue_from AccessDenied, :with => :access_denied_handler
private
@aishek
aishek / application.html.slim
Created August 17, 2014 08:30
can? example
# app/views/layouts/application.html.slim
doctype html
html
head
title Hello, world!
body
= render 'cart' if can? :buy
= yield
@aishek
aishek / purchases_controller.rb
Created August 17, 2014 08:33
authorize! example
class PurchasesController
def create
purchase = Purchase.new :user => current_user
authorize! :create, purchase
# purchase create logic
end
end
@aishek
aishek / six_example.rb
Created August 17, 2014 08:49
gem six basic usage example
# 1) Для экземпляров класса Purchase задаём правила,
# по которым определяем доступные над ними
# действия. В нашем случае разрешаем всем :create
class Purchase
def allowed(object, subject)
rules = []
return rules unless subject.kind_of?(Purchase)
rules << :create
@aishek
aishek / auth.rb
Created August 17, 2014 08:58
gem six auth concern
# app/controllers/concerns/auth.rb
module Concerns::Auth
extend ActiveSupport::Concern
class AccessDenied < RuntimeError; end
included do
helper_method :can?
@aishek
aishek / application_controller.rb
Last active August 29, 2015 14:05
gem six auth concern usage example
# app/controllers/web/application_controller.rb
class Web::ApplicationController < ApplicationController
include Concerns::Auth
rescue_from AccessDenied, :with => :access_denied_handler
private
@aishek
aishek / application_controller.rb
Last active August 29, 2015 14:05
gem six auth ror admin example
# app/controllers/web/admin/application_controller.rb
class Web::ApplicationController < Web::ApplicationController
include Concerns::Auth
rescue_from AccessDenied, :with => :access_denied_handler
private