This file contains 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 Car | |
class << self | |
def advertise(model) | |
puts "BUY IT NOW! #{model}" | |
end | |
def manufacture(make) |
This file contains 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 ask_for_age(name) | |
# We have to ask for this person's age | |
print "What is #{name}'s age? " | |
rand(100) # gets.chomp.to_i | |
end | |
# Roomful of People |
This file contains 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 JavascriptGenerator < Rails::Generators::NamedBase | |
def create_javascript_files | |
create_file "app/assets/javascripts/#{file_name}.coffee", "# New JavaScript File" | |
create_file "spec/javascripts/#{file_name}_spec.coffee", <<-SPEC | |
describe "test for #{file_name}", -> | |
This file contains 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
console: bundle exec rails console | |
rake: bundle exec rake | |
web: daemonized-worker & web | |
worker: worker |
This file contains 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
# Expirable is a module that lets you easily cache | |
# groups of records, either across an entire record: | |
# cache(Snippet) => cache(Snippet.cache_key) | |
# or, across a scope: | |
# cache(page.blocks) => cache(page.blocks.cache_key) | |
# | |
# Why not just use `maximum(:updated_at)`? | |
# Because it requires 2 queries: the total count, | |
# and the updated_at timestamp |
This file contains 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 calculator(operator, expression, *exprs) | |
exprs.each { |n| expression = expression.send(operator, n) } | |
expression | |
end |
This file contains 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
rails_admin do | |
configure :expertise do | |
bootstrap_wysihtml5 true | |
end | |
edit do | |
group 'Login' do | |
field :email | |
field :password do | |
visible false |
This file contains 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
How to setup Heroku Hostname SSL with GoDaddy SSL Certificate and Zerigo DNS | |
Heroku recently added an exciting new 'Hostname SSL' option. This option offers the broad compatibility of IP-based SSL, but at 1/5 the price ($20 / month at the time of this writing). | |
The following tutorial explains how to use Heroku's new 'Hostname SSL' option on your Heroku project. Before we begin, let's list what we're using here: | |
* Heroku Hostname SSL | |
* GoDaddy Standard SSL Certificate | |
* Zerigo DNS | |
Note: I am not using the Heroku Zerigo DNS add-on, instead I have a separate Zerigo account for my DNS needs. I do this because Zerigo offers 30 hosts on free direct accounts, versus only 10 hosts on the free Heroku add-on. |
This file contains 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 rpn expression | |
stack = [] | |
expression.split(' ').each do |token| | |
stack << if token =~ /\d/ | |
token | |
else | |
[stack.pop, stack.pop].map { |t| t.to_i }.inject do |sum, x| | |
eval "#{x} #{token} #{sum}" | |
end |