This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| named_scope :active, :conditions => {:active => true} | |
| def self.random | |
| self.active.find(:first, :order => ‘RAND()’) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace :db do | |
| namespace :fixtures do | |
| desc 'Create YAML test fixtures from data in an existing database. | |
| Defaults to development database. Set RAILS_ENV to override.' | |
| task :dump => :environment do | |
| sql = "SELECT * FROM %s" | |
| skip_tables = ["schema_info"] | |
| ActiveRecord::Base.establish_connection(:development) | |
| (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PORT = 22 | |
| USER = 'username' | |
| SERVER = 'server name or ip' | |
| DEST = 'web root on server' | |
| desc 'Builds site using StaticMatic' | |
| task :build do | |
| system 'staticmatic build .' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Contact | |
| include ActiveModel::Validations | |
| include ActiveModel::Serialization # should be => include ActiveModel::Serializers::Xml | |
| validates_presence_of :email, :subject, :body | |
| validates :email, :format => { | |
| :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i } | |
| attr_accessor :email | |
| attr_accessor :subject |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def output(data, format) | |
| case format | |
| when :html | |
| return "<p>#{data}</p>" | |
| when :text | |
| return data | |
| when :pdf | |
| return "<pdf>#{data}</pdf>" # pseudocode -- obviously not valid PDF output | |
| else | |
| raise ArgumentError, "Invalid format (#{format})." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| HTMLFormatter = lambda { |data| "<p>#{data}</p>" } | |
| TextFormatter = lambda { |data| data } | |
| PDFFormatter = lambda { |data| "<pdf>#{data}</pdf" } | |
| def output(data, format) | |
| case format | |
| when :html | |
| return HTMLFormatter.call(data) | |
| when :text | |
| return TextFormatter.call(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Lambda's are used here for simplicity. In reality each formatter would | |
| # probably be a separate class. | |
| FORMATTERS = { | |
| :html => lambda { |data| "<p>#{data}</p>" }, | |
| :text => lambda { |data| data }, | |
| :pdf => lambda { |data| "<pdf>#{data}</pdf>" } | |
| } | |
| def output(data, format) | |
| raise ArgumentError, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Range | |
| # Pick a random value from a Range. | |
| # === Example | |
| # (1..10).rand # => 3 | |
| def rand | |
| a = self.to_a | |
| a[Kernel::rand(a.size)] | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def rand_between(min, max) | |
| Kernel::rand(max-min+1) + min | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| git_bundles = [ | |
| "git://github.com/vim-bundles/fuzzyfinder.git", | |
| "git://github.com/scrooloose/nerdcommenter.git", | |
| "git://github.com/msanders/snipmate.vim.git", | |
| "git://github.com/tpope/vim-cucumber.git", | |
| "git://github.com/tpope/vim-haml.git", | |
| "git://github.com/tpope/vim-rails.git", | |
| "git://github.com/tpope/vim-surround.git" |
OlderNewer