Skip to content

Instantly share code, notes, and snippets.

View mrrooijen's full-sized avatar

Michael van Rooijen mrrooijen

View GitHub Profile
@mrrooijen
mrrooijen / Capistrano-Deployment-Recipe.rb
Created July 29, 2009 09:34
a "base" Capistrano Rails Deployment Recipe. Use it to deploy your Rails application. It is also easily expandable. So feel free to grab this Recipe and add your own tasks/customization!
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
@mrrooijen
mrrooijen / Git-Ignore
Created July 29, 2009 09:41
Git Ignore File for my Capistrano recipe
# Author: Michael van Rooijen
# Description:
# If you are using my Capistrano Recipe, be sure to add these lines to your .gitignore file.
# It will prevent problems when deploying incase your generated the all.js/all.css, assets, database.yml etc.
# Assets and Database yaml should be stored in the "shared" section of the application, not inside the actual application with every release.
.DS_Store
log/*.log
tmp/**/*
config/database.yml
@mrrooijen
mrrooijen / nginx
Created July 29, 2009 09:44
A script to enable easy start/stop functionality for the NginX Web Server.
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@mrrooijen
mrrooijen / jQuery-Plugin-Template.js
Created July 29, 2009 11:04
A jQuery Plugin Template.
(function($){
/**
* jQuery PluginName
*
* @plugin {PluginName}
* @description {PluginDescription}
*
* @changelog
* @{mm/dd/yyyy} {version} {author} {changedescription}
# Place this line below in your environment.rb to remove the Form Error Decorations that display when the form validation failed.
ActionView::Base.field_error_proc = proc { |input, instance| input }
# Inside the model.rb
has_attached_file :image,
:url => "/assets/images/:style/:id.:basename.:extension",
:path => ":rails_root/public/assets/images/:style/:id.:basename.:extension",
:styles => {
:small => '50x45#',
:medium => '150x150',
:large => '300x300'
}
.CodeRay {
background-color: #232323;
border: 1px solid black;
font-family: 'Courier New', 'Terminal', monospace;
color: #E6E0DB;
padding: 3px 5px;
overflow: auto;
font-size: 12px;
margin: 12px 0;
}
# Add this snippet into your ApplicationHelper to make it available to all views
# This method enables a simple but clean way to handle nested forms when a :has_many relationship
# along with the :accepts_nested_attributes_for methods are invoked in the model.
# Instead of making a method for each of the first arguments of the form_for() method, you can now just
# invoke the "nestable()" method and pass in the object in the first argument, followed by any associated/nested models.
# See the method and example comments below
module ApplicationHelper
# Call on first argument of the "form_for" method
# 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 %>
@mrrooijen
mrrooijen / 9.04.sh
Created September 4, 2009 13:16
Rails Stack Installer for Ubuntu 8.04/9.04. Ruby Enterprise Edition, Phusion Passenger, NginX, MySQL
# Author: Michael van Rooijen
# Description:
# A Rails Stack Installer for Ubuntu 8.04/9.04 with the light-weight and fast NginX Web Server.
# This shell script will install a basic Rails Stack with a bunch of useful and commonly used utilities.
# It will install Ruby Enterprise Edition with Phusion Passenger (Reduces Rails Application Memory Usage By Approx. 33%)
# It will install some essential gems like mysql, sqlite, postgres etc.
# It will install NginX Web Server
# It will install the MySQL database
# It will install Git
# It will install these utilities: ImageMagick, FFMpeg, Memcached