Skip to content

Instantly share code, notes, and snippets.

Michael van Rooijen mrrooijen

Block or report user

Report or block mrrooijen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Rails-Method-Nestable-(For-Nested-Forms).rb
# 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
View sortable_list_without_javascript.rb
# index.html.erb
<ul id="projects">
<% @projects.each_with_index do |project, index| %>
<% content_tag_for :li, project do %>
<%= %>
<%= 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 /
Created Sep 4, 2009
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
mrrooijen / block-like-configuration.rb
Created Nov 28, 2009
This is an example of a Block-like Configuration Template.
View block-like-configuration.rb
# The BlockConfiguration Class for storing the root-level
# configuration attributes
class BlockConfiguration
attr_accessor :attributes
%w(attr1 attr2 attr3).each do |method|
define_method method do |value|
attributes[method] = value
View OptionParser.rb
#!/usr/bin/env ruby
require 'optparse'
require 'pp'
# This hash will hold all of the options
# parsed from the command-line by
# OptionParser.
options = {}
View File.sub.gsub.rb
class File
def self.gsub(path, regexp, &block)
content =, &block), 'wb') { |file| file.write(content) }
def self.sub(path, regexp, &block)
content =, &block), 'wb') { |file| file.write(content) }
View gist:290757
#! /bin/sh
# 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
View mp3.rb
#! /usr/bin/env ruby
# Checks to see if the given utility is installed
def installed?(util)
%x(which #{util}).chomp!
# Makes the path or file friendly for UNIX environment
def make_friendly(file)
file.gsub("'", "\\'").gsub('"', '\\"').gsub(" ", "\\ ")
mrrooijen / YouTube.rb
Created Feb 11, 2010
A simple class that enables you to directly download a video from YouTube by simply providing the full YouTube URL.
View YouTube.rb
require 'rubygems'
require 'json'
require 'open-uri'
require 'progressbar'
# YouTube
# This class allows you to directly download videos straight from YouTube
# All you have to do is provide the full URL to a video on
# See the examples below!
class YouTube
mrrooijen / gist:331328
Created Mar 13, 2010
FFMPEG Commands for various video conversions.
View gist:331328
# FFMPEG Commands
# Playstation 3 / Sony Bravia HD TV Conversion
ffmpeg -y -i video.mkv -vcodec libx264 -level 41 -vpre normal -crf 24 -threads 0 -acodec libfaac -ab 128k -ac 2 -ar 48000 new_video.mp4
You can’t perform that action at this time.