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
# Example from Rick Olson's Sparklines middleware | |
# http://github.com/technoweenie/rack-sparklines/blob/master/lib/rack-sparklines.rb | |
module Rack | |
class Sparklines | |
def initialize(app, options = {}) | |
@app, @options = app, options | |
end | |
def call(env) | |
if env['PATH_INFO'][@options[:prefix]] == @options[:prefix] |
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
# 1) Point *.example.com in your DNS setup to your server. | |
# | |
# 2) Setup an Apache vhost to catch the star pointer: | |
# | |
# <VirtualHost *:80> | |
# ServerName example.com | |
# ServerAlias *.example.com | |
# </VirtualHost> | |
# | |
# 3) Set the current account from the subdomain |
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
# an example Monit configuration file for collectiveidea's fork of delayed_job. | |
# See: http://stackoverflow.com/questions/1226302/how-to-monitor-delayedjob-with-monit/1285611 | |
# | |
# To use: | |
# 1. replace {app_name} and {environment} as appropriate | |
# 2. copy to your repository under config/delayed_job.monitrc | |
# 3. add this to your /etc/monit/monitrc: | |
# | |
# include /var/www/apps/{app_name}/current/config/*.monitrc | |
# 4. reload monit when you deploy to pick up any changes to your monitrc files: sudo monit reload |
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 RAILS_ENV != 'development' | |
require 'cache_money' | |
config = YAML.load(IO.read(File.join(RAILS_ROOT, "config", "memcached.yml")))[RAILS_ENV] | |
$memcache = MemCache.new(config) | |
$memcache.servers = config['servers'] | |
$local = Cash::Local.new($memcache) | |
$lock = Cash::Lock.new($memcache) | |
$cache = Cash::Transactional.new($local, $lock) |
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
$ cat test.rb | |
class Person | |
end | |
Person.new | |
$ cat test.rb | irb | |
>> class Person | |
>> end | |
=> nil | |
>> |
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 random_password(size = 8) | |
chars = (('a'..'z').to_a + ('0'..'9').to_a) - %w(i o 0 1 l 0) | |
(1..size).collect{ chars[rand(chars.size)] }.join | |
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
begin | |
# check if memcached is running; if it is, use that instead of the default memory cache | |
Timeout.timeout(0.5) { TCPSocket.open("localhost", 11211) { } } | |
config.cache_store = :mem_cache_store, %w(localhost:11211), { :namespace => 'OI', :timeout => 60 } | |
$stderr.puts "Using memcached on localhost:11211" | |
rescue StandardError | |
config.cache_store = nil | |
$stderr.puts "memcached not running, caching to memory" | |
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
# If your workers are inactive for a long period of time, they'll lose | |
# their MySQL connection. | |
# | |
# This hack ensures we re-connect whenever a connection is | |
# lost. Because, really. why not? | |
# | |
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar) | |
# | |
# From: | |
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/ |
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
Factory.define :application do |factory| | |
factory.attachment(:sample, "public/samples/sample.doc", "application/msword") | |
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
require 'open-uri' | |
# url dsl -- the ultimate url dsl! | |
# | |
# You just can't beat this: | |
# | |
# $ irb -r url_dsl | |
# >> include URLDSL | |
# => Object | |
# >> http://github.com/defunkt.json |