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
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
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
#!/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
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
# n = number of additional customers per period | |
# p = amount each customer is charged per period | |
# a = duration of period to calculate total gross for | |
# | |
# example: customer every 2 weeks, 25 per month, after 6 months: (fn).call(2, 25, 6) | |
# => 1050 | |
->(n, p, a) { t = 0; a.times { |i| t += (i + 1) * p * n }; t } |
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
# if "key" equals "bird.jpg", | |
# then this code creates a smaller thumbnail of the bird, | |
# sized to 270 by 167 pixels, | |
# adding a watermark, | |
# compressing the thumbnail to save space, | |
# and saving the new thumbnail as "bird_medium.jpg" | |
Original.find(key).compress(70).resize(270, 167).to(:fit).watermark.save(:medium) |
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
module Railings | |
module Filterable | |
[:after, :before].each do |context| | |
[:index, :show, :new, :create, :update, :destroy].each do |action| | |
define_method "#{context}_#{action}", ->(filter, options = { }, &block) do | |
send "#{context}_filter", filter, options.merge!(:only => action), &block | |
end | |
end | |
end | |
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
# In a MongoMapper::Document, | |
# simply add | |
# key :password, Password | |
# your password will be automatically hashed, | |
# and you can compare plain-text passwords with the user's hashed password, ruby style: | |
# User.first.password == '1234' | |
# => true | |
# | |
# Also, prevents passwords from being leaked onto the console or error messages: | |
# User.first.password |
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
# constituent_importer.rb | |
# | |
# When the customer uploads an Excel file, | |
# we generate a unique ID for the file and | |
# store it on our AWS/S3 jobs bucket. | |
# | |
# Then we create a job with that unique ID, | |
# and our background workers execute the job as follows | |
class ConstituentImporter < Struct.new(:job_object_id) |