Skip to content

Instantly share code, notes, and snippets.

View mrrooijen's full-sized avatar

Michael van Rooijen mrrooijen

View GitHub Profile
# index.html.erb
<ul id="projects">
<% @projects.each_with_index do |project, index| %>
<% content_tag_for :li, project do %>
<%= project.name %>
<%= button_to('up', :action => 'sort', :projects => @projects.swap(index, index -1)) if index > 0 %>
<%= button_to('down', :action => 'sort', :projects => @projects.swap(index, index +1)) if index < @projects.length - 1 %>
<% end %>
<% end %>
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the mongodb data-store
# Description: starts mongodb using start-stop-daemon
@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
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
user app;
worker_processes 2;
error_log /home/app/logs/nginx.error.log info;
events {
worker_connections 1024;
}
gem 'resque', '>= 1.10.0'
gem 'heroku' # You will need the heroku gem for this too.
# lib/tasks/resque.rake
require 'resque/tasks'
task "resque:setup" => :environment do
ENV["VVERBOSE"] = "1" if Rails.env.development?
end
desc "Starts the heroku worker"
task "jobs:work" => :environment do
@mrrooijen
mrrooijen / monit.rc
Created May 7, 2011 14:32 — forked from anonymous/file1.ab
RVM + Monit
# thin
# assuming there's an appropriate .rvmrc in /path_to_rails_app/current
cd rails_app/current
gem install thin
rvm wrapper your_ruby@your_gemset your_app_name thin
# now we can use your_app_name_thin in Monit scripts
# /etc/monit.d
@mrrooijen
mrrooijen / rails_3_1_beta_1_changes.md
Created May 12, 2011 23:48 — forked from ryanb/rails_3_1_rc4_changes.md
The Changelogs for Rails 3.1 Beta 1

Railties 3.1 Beta 1

  • The -j option of the application generator accepts an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". As of this writing "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. Default is "jquery". [fxn]

  • jQuery is no longer vendored, it is provided from now on by the jquery-rails gem. [fxn]

  • Prototype and Scriptaculous are no longer vendored, they are provided from now on by the prototype-rails gem. [fxn]

  • The scaffold controller will now produce SCSS file if Sass is available [Prem Sichanugrist]

@mrrooijen
mrrooijen / backbone.rails.js
Created June 9, 2011 22:50 — forked from trydionel/backbone.rails.js
Makes Backbone.js play nicely with default Rails setup
//
// Backbone.Rails.js
//
// Makes Backbone.js play nicely with the default Rails setup, i.e.,
// no need to set
// ActiveRecord::Base.include_root_in_json = false
// and build all of your models directly from `params` rather than
// `params[:model]`.
//
// Load this file after backbone.js and before your application JS.