Skip to content

Instantly share code, notes, and snippets.

View mrrooijen's full-sized avatar

Michael van Rooijen mrrooijen

View GitHub Profile
@mrrooijen
mrrooijen / pushand.sh
Created June 21, 2010 20:14
Small PushAnd script.
#!/bin/bash
##
# Move into the ROOT of the application
cd ..
##
# Copy database.example.yml to database.yml
cp config/database.example.yml config/database.yml
@mrrooijen
mrrooijen / RFC-822-RSS-pubDate.rb
Created June 25, 2010 11:34
RFC-822 valid date/time string for RSS
require 'time'
require 'date'
Time.now.rfc2822
@mrrooijen
mrrooijen / Rails Modular Requiring
Created July 8, 2010 18:23
Require Rails' individual pieces
# require 'rails/all'
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
@mrrooijen
mrrooijen / gist:468861
Created July 9, 2010 00:42
MongoHQ Database URI Example
MongoHQ database URI example:
mongo://username:password@flame.mongohq.com:27065/database-name
@mrrooijen
mrrooijen / gist:470114
Created July 9, 2010 21:48
Stub Paperclip Attachment
##
# With regular RSpec stubbing
it 'should allow JPG images' do
photo = Photo.new :photo => fixture_file_upload('photos/chameleon.jpg', 'image/jpeg')
photo.stub!(:save_attached_files).and_return true
photo.save.should be_true
end
##
# With Mocha on "any" instance of a Class
@mrrooijen
mrrooijen / RVM Readline Issue
Created July 26, 2010 23:38
RVM ReadLine Issue
##
# Install the Readline package before installing ruby versions
rvm package install readline
##
# Then install a Ruby version with the readline path specified
rvm install ree -C --with-readline-dir=$HOME/.rvm/usr
module Dragonfly
module Endpoint
def success_headers(job)
{
"Content-Type" => job.app.resolve_mime_type(job.result),
"Content-Length" => job.size.to_s,
"Content-Disposition" => "filename=#{job.name}"
}.merge(cache_headers(job))
end
@mrrooijen
mrrooijen / delayed_job.rb
Created October 2, 2010 18:43
A replacement script for the one currently in HEAD.
#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
PID_DIR = File.join(RAILS_ROOT, 'tmp', 'pids')
Daemons.run_proc('delayed_job', { :dir => PID_DIR, :dir_mode => :normal }) do
ENV['RAILS_ENV'] ||= 'development'
Dir.chdir RAILS_ROOT
@mrrooijen
mrrooijen / Monitoring-DJ-with-GOD.god
Created October 3, 2010 03:42
A sample GOD config file for spawning a DJ worker instance.
RAILS_ROOT = File.dirname(File.dirname(__FILE__))
God.watch do |w|
w.name = 'dj-worker'
w.group = 'dj'
w.interval = 30.seconds
w.start = "rake -f #{RAILS_ROOT}/Rakefile -I #{RAILS_ROOT} RAILS_ENV=production jobs:work"
# retart if memory gets too high
w.transition(:up, :restart) do |on|
@mrrooijen
mrrooijen / flash_session_cookie_middleware.rb
Created October 14, 2010 19:32
For if you are using a Flash-based uploader like Uploadify and Rails 3.