Skip to content

Instantly share code, notes, and snippets.

@Danielpk
Danielpk / bank.rb
Created March 11, 2014 16:39
Rails custom validation
module Validators
class Bank
def initialize(agency, account)
@agency = agency
@account = account
end
def banco_do_brasil
agency = @agency.downcase
@Danielpk
Danielpk / gist:9477491
Created March 11, 2014 00:52
Rails conditional validation
with_options if: :is_step_new do
validates :name, :email, :phone, presence: true
validates_format_of :email, with: /@/, allow_blank: true
end
def is_step_new
# is_step('new')
false
end
@Danielpk
Danielpk / git-ignore
Created February 2, 2012 17:25
Generate .gitignore using GitHub/gitingore repository as source.
#!/bin/bash
# Every time you run this command the content will be append to .gitignore file.
# Usage:
# git ignore Drupal
# git ignore Global/OSX
# git ignore CakePHP
if [ "$#" != "1" ]; then
echo "Usage: git ignore path from http://github.com/github/gitignore"
@Danielpk
Danielpk / my_model.php
Created December 16, 2011 19:58
Relacionamento com Alias
$belongsTo = array(
'Atendimento' => array(
'className' => 'User',
'conditions' => array('type' => 'atendimento')
),
'Criacao' => array(
'className' => 'User',
'conditions' => array('type' => 'criacao')
),
);
@Danielpk
Danielpk / git-export-diff
Created November 7, 2011 18:31
Simple shell script to export changes between references.
#!/bin/bash
# Eq: git export-diff deploy.tar v1.2.3 HEAD
if [ "$#" != "3" ]; then
echo "Usage: git export-diff filename.tar ref1 ref2"
exit 2;
fi
filename=$1
ref1=$2