Skip to content

Instantly share code, notes, and snippets.

@rgo
rgo / validateable.rb
Created July 6, 2009 14:59
Validating non AR models in Rails 2.3
# From http://www.neeraj.name/blog/articles/810-validating-non-activerecord-models-in-rails-2-2
# Modified as said comment 1 - (changed self_and_descendents_from_active_record by self_and_descendants_from_active_record)
module Validateable
[:save, :save!, :update_attribute].each{|attr| define_method(attr){}}
def method_missing(symbol, *params)
if(symbol.to_s =~ /(.*)_before_type_cast$/)
send($1)
end
class Contact
include Validateable
attr_accessor :name,:phone, :email, :body
def initialize(options = {})
unless options.nil?
@name = options[:name] if options[:name]
@email = options[:email] if options[:email]
class ContactController < ApplicationController
def index
# render index.html.erb
end
def create
@contact = Contact.new(params[:contact])
if @contact.valid?
Notifications.deliver_contact(params[:contact])
#flash[:notice] = 'Email enviado correctamente'
@rgo
rgo / gist:144598
Created July 10, 2009 16:22
Create and apply patch with subversion
# Create and apply patch with subversion
svn diff > ~/fix_ugly_bug.diff
patch -p0 -i ~/fix_ugly_bug.diff
@rgo
rgo / gist:153049
Created July 23, 2009 15:03
Protect access to .svn directories.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} \.svn
RewriteRule ^.*$ - [F]
@rgo
rgo / gist:157111
Created July 28, 2009 10:54
503 for maintenance pages
# Show maintenance page if it exists
ErrorDocument 503 /system/maintenance.html
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ - [redirect=503,last]
@rgo
rgo / ubiquity.tmp-4.js
Created August 15, 2009 14:13
Ubiquity commands to search at apidock.com
// Tip: You can go to any result in preview by pressiong ctrl+alt+[result number]
CmdUtils.makeSearchCommand({
name: ["rails","rails-search"],
homepage: "http://rafagarcia.net/",
author: { name: "Rafa Garcia", email: "[email protected]"},
license: "GPL",
url: "http://apidock.com/rails/search/?query={QUERY}",
description: _("Searches Ruby on Rails terms in Apidock.com"),
icon: "http://apidock.com/images/rails_icon_16.png",
parser: {
@rgo
rgo / house-cleaning
Created September 9, 2009 23:33
Services moved from rc.M to cron.daily/house-cleaning (Improve boot time)
#!/bin/sh
# /etc/cron.daily/house-cleaning
# RGO - not commented in rc.M
# Update all the shared library links:
#if [ -x /sbin/ldconfig ]; then
# echo "Updating shared library links: /sbin/ldconfig &"
# /sbin/ldconfig &
#fi
@rgo
rgo / src2pkg_alsa.sh
Created October 27, 2009 00:59
Slackware: upgrade alsa
#!/bin/bash
#
# Instructions and dependencies:
# You must run it with admin privileges
# You need src2pkg to generate packages
# Working directory is where src and packages will be stored
#
# Based on scripts read in http://aldeby.org/blog/index.php/how-to-update-alsa-to-latest-version-easily.html
# Credits:
# 2007 Bob Nelson [email protected]
#!/bin/bash
# Show disk usage in directories
for file in `ls`; do sudo du -sh $file; done