Skip to content

Instantly share code, notes, and snippets.

View edison's full-sized avatar
🏠
Working from home

Edison Machado edison

🏠
Working from home
View GitHub Profile
@edison
edison / cpf_validator.rb
Created May 3, 2012 15:53
CPF Validator
class CpfValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, :invalid_cpf) unless valid_cpf?(value)
end
private
def valid_cpf?(cpf = nil)
return false if cpf.nil?
nulos = %w{12345678909 11111111111 22222222222 33333333333 44444444444 55555555555 66666666666 77777777777 88888888888 99999999999 00000000000}
@edison
edison / cnpj_validator.rb
Created May 3, 2012 15:52
CNPJ Validator
class CnpjValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, :invalid_cnpj) unless valid_cnpj?(value)
end
private
def valid_cnpj?(cnpj=nil)
return false if cnpj.nil?
nulos = %w{11111111111111 22222222222222 33333333333333 44444444444444 55555555555555 66666666666666 77777777777777 88888888888888 99999999999999 00000000000000}
@edison
edison / cruisecontrolrb
Created March 29, 2012 01:06
CruiseControl.rb init shell
#! /bin/sh
### BEGIN INIT INFO
# Provides: cruisecontrol.rb
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: CruiseControl.rb
# Description: Continuous build integration system. This runs the web interface.
### END INIT INFO
@edison
edison / gist:2223851
Created March 28, 2012 05:17 — forked from bryckbost/gist:1040263
Capybara 1.0 and Chrome
# env.rb
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Download chromedriver from http://code.google.com/p/selenium/downloads/list
mv chromedriver to /usr/local/bin so it's in your path.
// server
var net = require("net")
, server
;
server = net.createServer(function(socket){
// socket.end("bye\n");
socket.on("connect", function(){
console.log("conectou\n");
@edison
edison / will_paginate.rb
Created February 8, 2012 03:38 — forked from isaacbowen/will_paginate.rb
extends will_paginate to play well with Twitter's Bootstrap
# config/initializers/will_paginate.rb
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= BootstrapLinkRenderer
super.try :html_safe
end
class BootstrapLinkRenderer < LinkRenderer
@edison
edison / file_resource.rb
Created January 24, 2012 18:35 — forked from watson/file_resource.rb
Example Rails model using Paperclip and storing files on S3. This shows how to correctly set a custom header and saving the file in the correct location after it has been directly uploaded to from the users browser.
class FileResource < ActiveRecord::Base
has_attached_file :attachment,
:storage => :s3,
:bucket => ENV['S3_BUCKET'],
:s3_credentials => { :access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET'] },
:path => 'files/:id/:filename',
:url => '/files/:id/:filename'
@edison
edison / tokitozuska.rb
Created November 14, 2011 03:11
Tokitozuska
# RIKUTATAMO, KIRIN KA TOKITOZUSKA.
# KI MIKATO CHISHIKATOARITAKACHIKU KATOFUCHIRIKITOJI FUMODO MEIKATOCHI.
# KADOCHIRIMOSHI: KUTEKIARIMOTO RINKAMIRIKATEMO.
class Tokitozuska
@@mirikashiari = {
"a" => "ka",
"b" => "zu",
"c" => "mi",
"d" => "te",
@edison
edison / error_log
Created May 26, 2011 08:02
undefined method `delegate_template_exists?'
edison$ rails s
=> Booting Mongrel
=> Rails 3.1.0.rc1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/edison/.rvm/gems/ruby-1.9.2-p180/gems/haml-3.1.1/lib/haml/template/patch.rb:16:in `alias_method': undefined method `delegate_template_exists?' for class `ActionView::Base' (NameError)
from /Users/edison/.rvm/gems/ruby-1.9.2-p180/gems/haml-3.1.1/lib/haml/template/patch.rb:16:in `<class:Base>'
from /Users/edison/.rvm/gems/ruby-1.9.2-p180/gems/haml-3.1.1/lib/haml/template/patch.rb:12:in `<module:ActionView>'
from /Users/edison/.rvm/gems/ruby-1.9.2-p180/gems/haml-3.1.1/lib/haml/template/patch.rb:11:in `<top (required)>'
@edison
edison / log-2011-05-19
Created May 20, 2011 01:12
encoding error Rails 3.1
edison$ rails s
=> Booting WEBrick
=> Rails 3.1.0.beta1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-05-19 22:07:41] INFO WEBrick 1.3.1
[2011-05-19 22:07:41] INFO ruby 1.9.2 (2011-02-18) [x86_64-darwin10.7.0]
[2011-05-19 22:07:41] INFO WEBrick::HTTPServer#start: pid=4975 port=3000
Error during failsafe response: "\xC3" from ASCII-8BIT to UTF-8
/Users/edison/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.beta1/lib/active_support/buffered_logger.rb:104:in `write'