Skip to content

Instantly share code, notes, and snippets.

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

Jônatas Davi Paganini jonatas

🏠
Working from home
View GitHub Profile
#!/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})
CREATE ROLE mingle with login encrypted password 'mingle' superuser;
@jonatas
jonatas / gist:87763
Created March 30, 2009 12:10
list sorted by time
ls -S -t -lah | more
pg_dump -D -U nome_usuario -h 127.0.0.1 -i -f nome_arquivo.sql -n nome_schema -T ignorar_tabela nome_banco
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
quero alterar uma linha que começa com:
FROM tabela
para transformar em:
FROM
tabela
para buscar a sintaxe no vim:
/^FROM \(.*\)\(\n\)
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}"}
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]
$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
@jonatas
jonatas / fizz_buzz.rb
Created July 9, 2012 02:36
fizz buzz
(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