This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
full_name = "Leandro Parazito" | |
name_list = full_name.split() | |
greeting_list = "Hi, I'm x".split() | |
# Get last item in greeting_list | |
greeting_list[-1] = name_list[0] | |
greeting = " ".join(greeting_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
curl http://gist.github.com/raw/323731/install_homebrew > install_homebrew.rb | |
ruby install_homebrew.rb | |
rm install_homebrew.rb | |
echo "PATH=/usr/local/bin:/Developer/usr/bin:\$PATH; export PATH" >> ~/.profile | |
source ~/.profile | |
echo "Your path is now $PATH" | |
brew install git | |
brew update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run rake db:size to get a print of your database size in bytes. | |
# Run rake db:tables:size to get the sizes for individual tables | |
# Works for MySQL and PostgreSQL. Not tested elsewhere. | |
namespace :db do | |
desc 'Print data size for entire database' | |
task :size => :environment do | |
database_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:database] | |
adapter = ActiveRecord::Base.connection.adapter_name.downcase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
module Acts | |
module AsFlagable | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def acts_as_flagable(options) | |
unless flagable? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pedido < ActiveRecord::Base | |
def gera_numero_pedido | |
self.numero = Array.new(9){rand(9)}.join while self.numero.nil? or Pedido.find_by_numero(self.numero) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reincarnation for classes | |
class Class | |
def reincarnate | |
buried = Object.__send__(:remove_const, self.name) | |
Object.const_set(self.name, Class.new(buried)) | |
end | |
end | |
class Abc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AssertionExtensions | |
def method_missing(method_id, *arguments, &block) | |
return super unless method_id.to_s =~ /^assert_(not_)?(.*)$/ | |
method = "#{$2}?" | |
object = arguments.first | |
if $1 | |
arguments.each do |object| | |
assert ! object.send(method), "#{method} is not false for #{object}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails::Initializer.class_eval do | |
def load_application_initializers_with_plugin_initializers | |
if gems_dependencies_loaded | |
plugin_loader.load_plugin_initializers | |
end | |
load_application_initializers_without_plugin_initializers | |
end | |
alias_method_chain :load_application_initializers, :plugin_initializers | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Enumerable | |
def return(*) | |
if block_given? | |
each do |i| | |
value = yield(i) | |
return value if value | |
end | |
nil | |
else | |
super |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pg_dump -D -U nome_usuario -h 127.0.0.1 -i -f nome_arquivo.sql -n nome_schema -T ignorar_tabela nome_banco |
NewerOlder