Skip to content

Instantly share code, notes, and snippets.

View maxschulze's full-sized avatar

maxschulze maxschulze

View GitHub Profile
# super class that is stored in the database
class Message
...
end
class Linkedin::Message < Message
...
end
class Facebook::Message < Message
# super class that is stored in the database
class Message
...
end
module Linkedin
class Message < ::Message
...
end
@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
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 / 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