Skip to content

Instantly share code, notes, and snippets.

View maxschulze's full-sized avatar

maxschulze maxschulze

View GitHub Profile
@maxschulze
maxschulze / validates_uri_existence.rb
Created January 21, 2010 00:48
Rails URL Validation with :allow_blank
require 'net/http'
# Original credits: http://blog.inquirylabs.com/2006/04/13/simple-uri-validation/
# HTTP Codes: http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTPResponse.html
class ActiveRecord::Base
def self.validates_uri_existence_of(*attr_names)
configuration = { :message => "is not valid or not responding", :on => :save, :with => nil }
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
configuration[:with] = /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
rvm package install zlib
rvm package install iconv
rvm package install readline
rvm install 1.9.2-head -C --with-readline-dir=$HOME/.rvm/usr --with-iconv-dir=$HOME/.rvm/usr --with-zlib-dir=$HOME/.rvm/usr --with-openssl-dir=/usr/local
gem install linecache19 -- --with-ruby-include=/Users/USERNAME/.rvm/src/ruby-1.9.2-VERSION/
gem install ruby_core_source -- --with-ruby-include=/Users/USERNAME/.rvm/src/ruby-1.9.2-VERSION/
gem install ruby-debug-base19 -- --with-ruby-include=/Users/USERNAME/.rvm/src/ruby-1.9.2-VERSION/
@maxschulze
maxschulze / .autotest
Created October 9, 2010 18:45
Speed up autotest with excluding not needed rails app directories
require 'autotest/growl'
Autotest.add_hook :initialize do |at|
%w{.svn .hg .git vendor db public log script doc}.each {|exception| at.add_exception(exception)}
end
# super class that is stored in the database
class Message
...
end
module Linkedin
class Message < ::Message
...
end
# super class that is stored in the database
class Message
...
end
class Linkedin::Message < Message
...
end
class Facebook::Message < Message
@maxschulze
maxschulze / database_cleaner_config.rb
Created November 5, 2010 17:42
Database Cleaner configuration fuer cucumber mit I18n Backend Database
DatabaseCleaner.strategy = :truncation, { :except => %w[ translations ] }
describe User
it "should fetch Linkedin data on create for the profile"
it "should fetch Linkedin connections after create"
it "should fetch positions after fetch"
it "must have a linked in profile"
it "must have a linked in uid"
it "should be possible to update the data from linked in"
end
class Linkedin::Profile < ActiveRecord::Base
set_table_name 'linkedin_profiles'
belongs_to :user, :class_name => "Linkedin::User"
has_many :positions
has_many :educations
belongs_to :industry
belongs_to :location
@maxschulze
maxschulze / photo.rb
Created November 30, 2010 11:21 — forked from lawitschka/photo.rb
Save image size for paperclip photo
class Photo < ActiveRecord::Base
has_attached_file :image, :styles => { :thumb => ['150x150#', :png],
:normal => ['660x660', :png] },
:default_style => :normal
typed_serialize :sizes, Hash
before_save :cache_image_sizes
# Get size of this photo for specified style
#