Skip to content

Instantly share code, notes, and snippets.

View rdavila's full-sized avatar

Rubén Dávila Santos rdavila

View GitHub Profile
class Test::Unit::TestCase
def self.should_require_login(*args)
args = Hash[*args]
login_url = args.delete :login_url
args.each do |action, verb|
should "Require login for '#{action}' action" do
send(verb, action)
assert_redirected_to(login_url)
end
end
run "rm public/index.html"
#Dependencies
gem "haml"
gem "thoughtbot-factory_girl", :lib => "factory_girl", :source => "http://gems.github.com"
gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com"
#!/usr/bin/env ruby
require 'fileutils'
module GitScripts
class Branch
attr_reader :name
def initialize(path)
@path = path
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
function proml {
local BLUE="\[\033[0;34m\]"
local RED="\[\033[0;31m\]"
local LIGHT_RED="\[\033[1;31m\]"
local GREEN="\[\033[0;32m\]"
local LIGHT_GREEN="\[\033[1;32m\]"
set go-=T
set bg=dark
if has("gui_running")
"set fuoptions=maxvert,maxhorz
"au GUIEnter * set fullscreen
endif
if &background == "dark"
hi normal guibg=black
endif
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
<%
output = `cd #{Rails.root} && git branch`
branch = output.select { |e| e =~ /\A\*.+/ }.first
actual_branch = branch[/\*\s(.+)/, 1]
%>
development:
adapter: sqlite3
database: db/<%= actual_branch %>_db
@rdavila
rdavila / git_prompt_bash
Created December 11, 2010 00:35
git_prompt_bash
function prompt {
local LIGHT_RED="\[\033[1;31m\]"
local LIGHT_GREEN="\[\033[1;32m\]"
local NO_COLOUR="\[\033[0m\]"
local TITLEBAR='\[\033]0;\u@\h\007\]'
source ~/.git-completion.bash
export GIT_PS1_SHOWDIRTYSTATE=true
@rdavila
rdavila / config.log
Created August 18, 2011 22:43
Can't install postgres on Snow Leopard 10.6.8
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by PostgreSQL configure 9.0.4, which was
generated by GNU Autoconf 2.63. Invocation command line was
$ ./configure --disable-debug --prefix=/usr/local/Cellar/postgresql/9.0.4 --enable-thread-safety --with-bonjour --with-gssapi --with-krb5 --with-openssl --with-libxml --with-libxslt --with-python --with-perl --with-ossp-uuid --datadir=/usr/local/Cellar/postgresql/9.0.4/share/postgresql --docdir=/usr/local/Cellar/postgresql/9.0.4/share/doc/postgresql ARCHFLAGS='-arch x86_64'
## --------- ##
## Platform. ##
@rdavila
rdavila / gist:1195843
Created September 5, 2011 20:25
sql logger
ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
def log_with_syspanel_logger(sql, name, &block)
if Thread.current["syspanel.sql.logger.enabled"]
Thread.current["syspanel.sql.logger.enabled"] = false
SyspanelSqlLog.create(:sql => sql, :name => name)
end
log_without_syspanel_logger(sql, name, &block)
end
@rdavila
rdavila / ar_extension.rb
Created September 6, 2011 16:20
Problem to log AR queries to DB
class ActiveRecord::ConnectionAdapters::MysqlAdapter
def execute(sql, name = nil, skip_logging = false)
log(sql, name) { @connection.query(sql) } unless skip_logging
rescue ActiveRecord::StatementInvalid => exception
if exception.message.split(":").first =~ /Packets out of order/
raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
else
raise
end