Skip to content

Instantly share code, notes, and snippets.

View zaparka's full-sized avatar

Petr Zaparka zaparka

View GitHub Profile
@zaparka
zaparka / cout.rb
Created May 2, 2017 10:42
Using only alphabetical uuid for slug with friendly_id gem
class Court < ActiveRecord::Base
validates_format_of :slug, with: /\A[a-zA-Z-]+\z/, allow_nil: true
extend FriendlyId
friendly_id :slug_candidates, use: [:slugged, :history, :finders]
private
def slug_candidates
candidates = [:name]
user = User.first
user.avatar.file.exists?
@zaparka
zaparka / gist:3089382
Created July 11, 2012 09:57
Uploader class
class AvatarUploader < CarrierWave::Uploader::Base
storage :fog
end
@zaparka
zaparka / gist:3089378
Created July 11, 2012 09:57
User class
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
@zaparka
zaparka / gist:1319124
Created October 27, 2011 09:14
textmate folder pattern
!.*/(\.[^/]*|vendor/.*|doc|rails_root|CVS|log|data_dump|build|_darcs|pkg |_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)? |bundle))$
@zaparka
zaparka / paperclip_gist.rb
Created September 14, 2011 10:30
Paperclip interpolation - customising upload path
#paperclip.rb in config/initializers
Paperclip.interpolates :created_at do |attachment, style|
attachment.instance.created_at.to_i
end
# path in your model will look like this
# :path => ":attachment/gallery/:id/:created_at/:style.:extension"
@zaparka
zaparka / rsa_decryption
Created December 9, 2010 11:39
rsa decryption via OpenSSL lib
certificate = OpenSSL::X509::Certificate.new(File.read("#{Rails.root}/certificate.pem"))
#public key from certificate
public_key = cert.public_key
#or public key from file
public_key = OpenSSL::PKey::RSA.new("#{Rails.root}/public_key.pem")
clear_text = public_key.public_decrypt(encrypted_text)
@zaparka
zaparka / gist:656820
Created October 31, 2010 16:49
s3 and paperclip
this file http://github.com/qoobaa/s3.git belongs to config/initializers/
In your Model:
has_attached_file :picture,
:styles => {
:banner => '475x233#',
:thumbnail => '111x50#'
},
:storage => :s3,
$('.it')
.bind('enqueued', function() {...})
.bind('running', function() {...})
.bind('passed', function() {...})
.bind('failed', function(e, reason) {...})
$(Screw)
.bind('loading', function() {...})
.bind('loaded', function() {...})
.bind('before', function() {...})
Screw.Matchers["be_even"] = {
match: function(expected, actual) {
return actual % 2 == 0;
},
failure_message: function(expected, actual, not) {
return 'expected ' + $.print(actual) + (not ? ' not' : '') + ' to be even';
}
}