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 Estimated < Other; end | |
class Forwarded < Other; end | |
case discussable | |
when Estimated then :queued # discussable.estimate? | |
when Forwarded then :read # discussable.forward? | |
else :unread | |
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
#!/usr/bin/env ruby | |
# script/rails | |
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. | |
# Automatically kill zombie Thin servers when booting up a rails server | |
if ENV['RACK_ENV'] == 'development' && pid = `ps -ef | grep thin | grep -v grep | sort -r | sed -n 2p | awk '{print $2}'` | |
puts "=> Killing existing server with pid #{pid}" | |
`kill -9 #{pid}` | |
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
gem 'heroku' |
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
namespace :paperclip do | |
# Fix broken timestamps | |
task :fix => :environment do | |
# All user picture files in the production environment (directories[1]) | |
files = User.last.picture.send(:connection).directories[Rails.env.staging? ? 2 : 1].files.select do |file| | |
file.key.starts_with?('users/pictures') | |
end.sort_by(&:last_modified) | |
(0..300).each do |ranged| | |
puts "Ranged: #{ranged}" |
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
# Throw this into config/initializers/cache.rb | |
if ARGV.any? { |a| %w(s server thin).include?(a) } | |
puts "=> Initializing environment, clearing cache" | |
Rails.cache.clear | |
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
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 |
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
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
def calculator(operator, expression, *exprs) | |
exprs.each { |n| expression = expression.send(operator, n) } | |
expression | |
end |