This file contains hidden or 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
#!/usr/bin/env ruby | |
# traduz uma frase de ingles para portugues | |
require 'rubygems' | |
require 'httparty' | |
class GoogleApi | |
include HTTParty | |
base_uri 'ajax.googleapis.com' | |
def self.translate(string="", to="pt", from="en") | |
get("/ajax/services/language/translate", :query => {:langpair => "#{from}|#{to}", :q => string, :v => 1.0}) |
This file contains hidden or 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
CREATE ROLE mingle with login encrypted password 'mingle' superuser; |
This file contains hidden or 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
ls -S -t -lah | more |
This file contains hidden or 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 |
This file contains hidden or 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
Dir['*_test.rb'].each do |file| | |
puts file | |
linhas = File.readlines(file) | |
File.open(file, 'w+') do |f| | |
f.puts(linhas.collect do |linha| | |
linha.gsub(/Test::Unit::TestCase/,'ActiveSupport::TestCase') | |
end) | |
end | |
end |
This file contains hidden or 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
quero alterar uma linha que começa com: | |
FROM tabela | |
para transformar em: | |
FROM | |
tabela | |
para buscar a sintaxe no vim: | |
/^FROM \(.*\)\(\n\) |
This file contains hidden or 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
jonatas@ogro:~/projetos/rails/agecel$>time ruby <<TESTE | |
> teste = proc {|i| "teste"+i.to_s} | |
> 1000000.times &teste | |
> TESTE | |
real 0m2.170s | |
user 0m1.808s | |
sys 0m0.352s | |
jonatas@ogro:~/projetos/rails/agecel$>time ruby <<TESTE | |
> teste = proc {|i| "teste#{i}"} |
This file contains hidden or 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 Delegate | |
def self.included(base) | |
base.class_eval do | |
def method_missing(name, *args, &block) | |
self.send(@@delegators[name]).send name, *args, &block | |
end | |
class << self | |
def delegate method, options | |
(@@delegators ||= {})[method] = options[:to] |
This file contains hidden or 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
$objetos = {} | |
class Object | |
def objeto(nome) | |
$objeto = $objetos[nome] = Object.new | |
end | |
def method_missing(nome, *args, &block) | |
$objetos[nome.to_s] || | |
$objeto.instance_variable_get("@#{nome}") || | |
super | |
end |
This file contains hidden or 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
(1..100).to_a.each do |i| | |
multiple_three = i % 3 == 0 | |
multiple_five = i % 5 == 0 | |
puts "#{i} #{[ ('Fizz' if multiple_three), | |
('Buzz' if multiple_five) | |
].compact.join("-")}" | |
end |
OlderNewer