gem install rails
rails new my_app -T
| # Shell commands | |
| alias @='pwd' | |
| # Bundler | |
| alias brake='bundle exec rake' | |
| alias be='bundle exec' | |
| # Rails 2 | |
| alias sc='script/console' | |
| alias sg='script/generate' |
| class SmartEnumerator < Enumerator | |
| attr_reader :length | |
| def initialize(enumerable) | |
| super | |
| @length = enumerable.length | |
| end | |
| def each | |
| self.each_with_index do |item, index| |
| body, table, td, th, p, a, img { margin:0 auto; padding:0; } | |
| thead, tbody, tr { margin:0; padding:0; } | |
| body, table.body-table, table.body-table td.body-td { | |
| background-color:#ffffff; | |
| color:#333333; | |
| font-family:"Lucida Grande", Arial, Helvetica, sans-serif; | |
| font-size:16px; | |
| line-height:24px; | |
| margin:0; |
| // Sums all "number" arguments given. This includes floats by default. | |
| // | |
| // sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); //=> 55 | |
| // sum(1, "hey", 2, "3", 4, "five", 6, 'hi!', 7, 8.2, 9, 10); //=> 47.2 | |
| function sum() { | |
| var sum = 0; | |
| for (i = 0; i < arguments.length; i++) { | |
| var arg = arguments[i]; | |
| if (typeof arg === 'number') sum += arg; | |
| } |
| class String | |
| # alias the method_missing method chain so that we can use single-word booleans | |
| # for example, we can do things like "standard".standard? which will give us true | |
| # obviously this is most suited for cases where you have a variable with a value from a known set of values | |
| def method_missing_with_single_word_booleans(method_name, *args, &block) | |
| return method_missing_without_single_word_booleans(method_name, *args, &block) unless method_name.to_s =~ /^(\w+)\?$/ | |
| self == $1 | |
| end | |
| alias_method_chain :method_missing, :single_word_booleans | |
| end |
| # Create a ViewHelper class or module (whatever) for dealing with flash messages in an easy-to-use format | |
| # the current way: | |
| <%- if flash[:error] -%> | |
| <p class="error"><%= flash[:error] %></p> | |
| <%- end -%> | |
| <%- if flash[:notice] -%> | |
| <p class="notice success"> | |
| <%= flash[:notice] %> <%= link_to('View Now', view_post_path) if post_created %> | |
| </p> |
| # Leopard Development Environment (from clean installation) | |
| # Replace USERNAME with your OS X short name. | |
| # Replace PASSWORD with your MySQL root password. | |
| # Install XCode Tools | |
| # Install MacPorts | |
| # Install Textmate | |
| # Generate an SSH key | |
| ssh-keygen |
| # Having some fun with a simple Fibonacci sequence Hash! | |
| fibonacci = Hash.new {|hash, key| hash[key] = hash[key - 1] + hash[key - 2]} | |
| #=> {} | |
| # Gotta get things started here… | |
| fibonacci[1] = 1 | |
| #=> 1 |