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
| # Create a Tag URI for the given +article+ | |
| # (See http://www.taguri.org/) | |
| # Should return something along the lines of: | |
| # tag:example.org,2008-12-01:/articles/1 | |
| def tag_uri(article) | |
| tag = absolute_url(:article, :id => article) | |
| tag.gsub!(/^http:\/\//, 'tag:') | |
| tag.gsub!('#', '/') | |
| pub_date = article.created_at.strftime("%Y-%m-%d") | |
| tag.gsub!(/#{request.host}/, "#{request.host},#{pub_date}:") |
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 next_page(format = 'markdown') | |
| chapter = params[:chapter] || :toc | |
| page_name = params[:page_name] | |
| current_file = Dir["#{Merb.root}/book-content/#{language}/*-#{chapter}/*-#{page_name||"*"}.#{format}"].entries.first | |
| if current_file | |
| current_file.grep(/book-content\/\w{2}\/(\d{1,})[-]\w+[-]\w+\/(\d{1,})[-]\w+[.]\w+/) | |
| chapter_number = $1 | |
| page_number = $2 | |
| end | |
| next_file = Dir["#{Merb.root}/book-content/#{language}/#{chapter_number}-*/#{page_number.to_i + 1}-*.#{format}"].entries.first |
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/local/bin/ruby | |
| require 'rubygems' | |
| require 'mongrel' | |
| # Add the request handler directory to the load path. | |
| # Files in the 'app/controllers' dir will be mapped against the first segment | |
| # of a URL | |
| $LOAD_PATH.unshift( File.join( File.dirname( __FILE__ ) , 'app/controllers' ) ) | |
| PORT = 4000 |
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
| # in the model: | |
| def self.all_by_date(year, month, order = [:created_at.desc]) | |
| year = year.to_i | |
| start_month = month ? month.to_i : 1 | |
| start_day = 1 | |
| start_date = Date.new(year, start_month, start_day) | |
| end_month = month ? month.to_i : 12 | |
| end_day = days_in_month(year, end_month) |
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
| # Sinatra powered Rock, Paper, Scissors! | |
| require 'rubygems' | |
| require 'sinatra' | |
| configure do | |
| TITLE = 'Sinatra powered Rock, Paper, Scissors!' | |
| RPS = %w(rock paper scissors) | |
| RPSSL = RPS + %w(spock lizard) | |
| 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
| # Return the given key's value from the (CakePHP) database config | |
| # file. This will read through the config string looking for | |
| # 'key' => 'value' pairs in the PHP array. Then, it will | |
| # strip newlines, spaces, and substitute any quotes. | |
| # | |
| # I use this in a Rakefile I created to help ease the | |
| # pain of working with CakePHP. | |
| # | |
| # Usage: | |
| # File.open('database.php') do |f| |
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
| # A Rakefile I use to ease the pain of working with CakePHP. | |
| # Put this in your app/ directory. | |
| APP_DIR = File.dirname(__FILE__) | |
| CAKE_DIR = File.join(File.dirname(__FILE__), '..', 'cake') | |
| CONSOLE_DIR = File.join(CAKE_DIR, 'console') | |
| task :default => 'notes:todo' | |
| desc 'Open the CakePHP console' |
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
| require 'json' | |
| require 'open-uri' | |
| # Access the latest Twitter trends. | |
| # | |
| # Usage: | |
| # | |
| # TweetTrend.new.display | |
| # | |
| # - or - |
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
| ~2 days per pack | |
| 20 smokes per pack | |
| 10 packs in a carton | |
| smoking for 7 years | |
| 7 * 365 = 2555 days | |
| 2555 days / 2 (packs/day) = 1277.5 packs |
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 RubyProj | |
| def self.create(name) | |
| %x| mkdir #{name} | | |
| %x| touch #{name}/Rakefile | | |
| %x| mkdir -p #{name}/lib | | |
| %x| touch #{name}/lib/#{name}.rb | | |
| %x| mkdir -p #{name}/spec | | |
| %x| touch #{name}/spec/spec_helper.rb | | |
| %x| touch #{name}/spec/#{name}_spec.rb | | |
| end |