Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar

Vladimir Dementyev palkan

View GitHub Profile
@palkan
palkan / gist:beaf6bc52b125cc7a26c
Last active August 29, 2015 14:14
Page classnames stats
window._collect_css = (function(){
var ALPHABET_SIZE=36, classnames={},
data = {
total_elements: null,
total_classes: null,
avg_length: null,
compressed_length: null,
total_class_length: 0,
total_class_count: 0,
total_size: 0,
@palkan
palkan / gist:c1ae6f56b8e718e7941f
Last active August 29, 2015 14:15
Ruby method_missing bench
require 'benchmark'
_methods = ("a".."z").to_a
module A
module B
module C
module D
module E
class X
@palkan
palkan / test.rb
Last active August 29, 2015 14:15
Rails issue #18695
# Activate the gem you are reporting the issue against.
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'activerecord', '4.2.0'
gem 'pg', '0.18'
gem 'pry-byebug'
GEMFILE
system 'bundle'
@palkan
palkan / main.rb
Last active August 29, 2015 14:16
"Restore" S3 assets after updating Paperclip hash_data
# Suppose we updated our hash_data for Paperclip
OLD_HASH = ":class/:attachment/:id/:style"
NEW_HASH = ":class/:attachment/:id/:style/:updated_at"
ACL = :public_read
def restore(r)
return unless r.file.exists?
new_key = r.file.path[1..-1]
r.file.options[:hash_data] = OLD_HASH;
.pi@session_cont
.pi-select.pi data-on-changed="@host.date.text(@this.selected_record().dates)"
...
ul.list
li.item data-id="#{@id}" data-dates="#{@period}"
...
.pi.date@date
@palkan
palkan / gist:731e27c44d730e13ce32
Last active August 29, 2015 14:22
NestedForm + CarrierWave
= nested_form_for answer, remote: true, ... do |f|
...
= f.fields_for :attachments do |attachment_form|
- if attachment_form.object.file.present?
p = attachment_form.object.file.identifier
- else
= attachment_form.label :file
= attachment_form.file_field :file
= attachment_form.link_to_remove "Remove this file"
= f.link_to_add "Add file", :attachments
@palkan
palkan / gist:c1a08ac2b4f141ab00cd
Last active August 29, 2015 14:24
Rubocop bug report
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rubocop', github: 'bbatsov/rubocop'
GEMFILE
system 'bundle'
end
require 'bundler'
@palkan
palkan / pundited.rb
Created July 25, 2015 13:51
Pundit#authorize_with
# Auhtorize any record to any policy
def authorize_with(klass, record, query = nil)
query ||= "#{action_name}?".to_sym
@_pundit_policy_authorized = @_policy_authorized = true # two vars for forward compatibility
policy = klass.new(pundit_user, record)
unless policy.public_send(query)
error = Pundit::NotAuthorizedError.new("not allowed to #{query} this #{record}")
error.query = query
error.record = record
error.policy = policy
@palkan
palkan / main.rb
Created August 5, 2015 14:36
Persistance#become bug
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 'arel', github: 'rails/arel'
@palkan
palkan / main.rb
Last active August 29, 2015 14:26
Issue 21116
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 'arel', github: 'rails/arel'