Skip to content

Instantly share code, notes, and snippets.

View reu's full-sized avatar

Rodrigo Navarro reu

View GitHub Profile
module FormHelper
def nested_form_for(object, *args, &block)
concat form_for(object, *(args << { :builder => NestedFormBuilder }), &block)
execute_after_nested_form_callbacks
end
def execute_after_nested_form_callbacks
@after_nested_form_callbacks ||= []
@after_nested_form_callbacks.inject(String.new.html_safe) do |output, callback|
output << callback.call
@reu
reu / ssh-copy-id
Created February 3, 2011 13:45
ssh-copy-id
#!/bin/sh
# Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.
ID_FILE="${HOME}/.ssh/id_rsa.pub"
if [ "-i" = "$1" ]; then
class NewYachtModel < ActiveRecord::Base
belongs_to :new_yacht
has_many :contents, :class_name => 'NewYachtTopicContent'
has_many :topics, :class_name => 'NewYachtTopic', :through => :contents
accepts_nested_attributes_for :contents
end
class NewYachtTopic < ActiveRecord::Base
require "benchmark"
n = 100000
klass = Benchmark
Benchmark.bm do |b|
b.report do
n.times { "visit_#{(klass.name || '').gsub('::', '_')}" }
end
@reu
reu / deploy.rb
Created November 6, 2010 12:41
Capistrano deploy recipe for database configuration
# Bundler Integration
require "bundler/capistrano"
# Application Settings
set :application, "yourapplicationname"
set :user, "serveruser"
set :deploy_to, "/home/#{user}/rails-applications/#{application}"
set :rails_env, "production"
set :use_sudo, false
set :keep_releases, 3
@reu
reu / gist:641354
Created October 22, 2010 20:55
lol.rb
def get(name, type = :string)
parameter = name.is_a?(Array) ? self.key_chain(*name) : self[name]
if !parameter.blank?
case type
when :string then parameter.to_s
when :hash, :collection then parameter
when :csv then parameter.split(',').map(&:strip)
when :integer then Integer(parameter)
when :float then Float(parameter)
class Screenshoter
include Java
import java.io.File
import java.awt.Robot
import java.awt.Toolkit
import java.awt.Rectangle
import javax.imageio.ImageIO
def self.shoot!(output = "screenshot.png")
class CQM < ActiveRecord::Base
self.abstract_class = true
establish_connection(
:adapter => "mysql2",
:host => "localhost",
:username => "root",
:password => "root",
:database => "cqm_development"
)
require "ostruct"
module FormsHelper
def search_form_for(object_name, options={}, &block)
options[:html] = {:method => :get}.update(options[:html] || {})
object = OpenStruct.new(params[object_name])
form_for(object_name, object, options, &block)
end
end
apply 'http://gist.github.com/raw/562316/1c45aa71f17491c36d74123abf7886b9a08daddf/basic_stack.rb'
apply 'http://gist.github.com/raw/562316/ed62987b05de614c9b37062f410a3a48e4e776f2/brazilian_app.rb'
apply 'http://gist.github.com/raw/562316/56326e84aa23d9ac1cc227f8aa8ae178f2d4d6b5/cleanup.rb'
apply 'http://gist.github.com/raw/562316/7406f13bf9d9b9d467f3d00a26b56a960685beeb/rspec.rb'
apply 'http://gist.github.com/raw/562316/ad35700fa4f3cf9163b0149b19beeba0407ea325/cucumber.rb'
apply 'http://gist.github.com/raw/562316/4cc84eb5ea709c2f0ea76783157548a660a374a2/w3.rb'