Skip to content

Instantly share code, notes, and snippets.

class Remote
def initialize(door)
@door = door
end
def press_button
puts "Pressing the remote control button..."
if @door.is_open
@door.close
class CustomReports
def self.relatorio_geral(imobiliaria,tipo, collection, block)
RGhost::Document.new :paper => :A4, :margin_left => 0.2, :margin_right => 0.2, :margin_bottom => 2 do |doc|
doc.define_tags do
tag :small, :name => 'Verdana', :size => 12
tag :default, :name => 'Verdana', :size => 15
tag :title, :name => 'Verdana', :size => 17
tag :header1, :name => 'Verdana', :size => 20
tag :header2, :name => 'Verdana', :size => 26
end
import java.io.FileWriter;
import java.io.IOException;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class Logger implements HttpSessionListener{
module PrecoReal
def self.included( base )
@base = base
end
def atributo_em_real(*args)
args.each do |arg|
def show
@page_title = @cliente
@imoveis = @cliente.imoveis
@alugueis_atuais = Aluguel.atuais.all( :conditions => { :imovel_id => @imoveis.map(&:id) } )
@imoveis_alugados = Imovel.all( :conditions => {:id => @alugueis_atuais.map(&:imovel_id)})
@alugueis_anteriores = @cliente.alugueis
@contas = @cliente.contas.a_vencer
@atendimentos = @cliente.atendimentos
@contas_imoveis_all = imobiliaria_atual.contas.all( :conditions => { :referente_id => @alugueis_atuais.map(&:id), :referente_type => 'Aluguel' } )
@contas_imoveis = if params[:busca_de_contas].blank?
public void removerLojas(){
Query query = manager.createQuery("select l from Loja l");
List<Loja> lojas = query.getResultList();
Loja loja = lojas.get(0);
List<Produto> produtos = loja.getProdutos();
Produto produto = produtos.get(0);
package controllers;
import helpers.Redirector;
import helpers.Resource;
import java.io.IOException;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.redirect = new Redirector(request, response);
if (request.getParameter("id")==null){
if (request.getMethod().equals("POST"))
this.doCreate(request, response);
else
if (request.getParameter("method")!=null)
this.doNew(request, response);
desc "Move paths to more specific tables."
task :path_moving => :environment do
filetemp = "tmp/temp.sql"
File.open(filetemp, 'w') do |file|
Path.paginated_each do |path|
if path.user_agent =~ /[B|b]ot|[B|b]aidu|[S|s]pider/
file.puts "insert into `spiders_paths` (#{path.attribute_names.map{|attr| "`#{attr}`"}.join(', ')})
values(#{path.attribute_names.map{|attr| "#{path.send(attr).blank? ? 'NULL' : "'#{path.send(attr).to_s.gsub(/[']/, '\\\\\'')}'"}"}.join(', ')});\n"
else
file.puts << "insert into `customers_paths` (#{path.attribute_names.map{|attr| "`#{attr}`"}.join(', ')})
desc "Moves all generated paths into different tables depending on their source (human or bots/spiders)."
task :path_moving => :environment do
database = Path.configurations[RAILS_ENV]['database']
filetemp = "tmp/temp.sql"
last_id = nil
spiders = /[B|b]ot|[B|b]aidu|[S|s]pider|pingdom|xenu|sitemaps|cuil|msn|shopwiki|entireweb|tokenizer|ysearch/
File.open(filetemp, 'w') do |file|
Path.paginated_each(:per_page => 200) do |path|
type = path.user_agent =~ spiders ? 'spiders' : 'humans'
file.puts "insert into `#{type}_paths` (#{path.attribute_names.map{|attr| "`#{attr}`"}.join(', ')})