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 | |
| require Dir | |
| unless ARGV[0] | |
| puts 'Usage: newpost "the post title"' | |
| exit(-1) | |
| end | |
| blog_root = "/Users/jrk/proj/blog" |
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
| EM.add_periodic_timer(1) do | |
| Job.all_queued do |job| | |
| # perform job action | |
| 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
| module ActionView | |
| module Helpers | |
| # CaptureHelper exposes methods to let you extract generated markup which | |
| # can be used in other parts of a template or layout file. | |
| # It provides a method to capture blocks into variables through capture and | |
| # a way to capture a block of markup for use in a layout through content_for. | |
| module CaptureHelper | |
| # The capture method allows you to extract part of a template into a | |
| # variable. You can then use this variable anywhere in your templates or layout. | |
| # |
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 Integer | |
| def tries(options={}, &block) | |
| attempts = self | |
| exception_classes = options[:on] || Exception | |
| exception_classes = exception_classes.is_a?(Array) ? exception_classes : [exception_classes] | |
| begin | |
| return yield | |
| rescue *exception_classes | |
| retry if (attempts -= 1) > 0 |
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
| module Configuration | |
| def self.attributes | |
| @attributes | |
| end | |
| def self.configure | |
| base = ConfigBlock.new | |
| yield base | |
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
| module PercentagePatch | |
| module InstanceMethods | |
| def as_percentage_of(total) | |
| return 0 if total == 0 | |
| self.to_f / total * 100 | |
| end | |
| 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
| require 'rubygems' | |
| require 'sinatra' | |
| require 'redis' | |
| # To use, simply start your Redis server and boot this | |
| # example app with: | |
| # ruby example_note_keeping_app.rb | |
| # | |
| # Point your browser to http://localhost:4567 and enjoy! | |
| # |
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
| # With macro | |
| has_many :comments, :foreign_key => 'commentable_id', :conditions => "commentable_type = 'User'", :dependent => :destroy | |
| # Without macro | |
| def comments | |
| Comment.find_by_sql <<-SQL | |
| SELECT * FROM comments C | |
| WHERE C.commentable_id IS #{self.id} | |
| AND C.commentable_type IS 'User' | |
| SQL |
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
| module Configuration | |
| def self.attributes | |
| @attributes | |
| end | |
| def self.configure | |
| base = ConfigBlock.new | |
| yield base | |
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
| Configuration.configure do |config| | |
| config.support_email = "josh@example.net" | |
| config.google_analytics_key = "UA-x343x-SDS" | |
| config.twitter.screen_name = "joshnesbitt" | |
| config.twitter.password = "mypassword" | |
| end | |
| puts Configuration.support_email | |
| puts Configuration.google_analytics_key |