Skip to content

Instantly share code, notes, and snippets.

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

Rafael Ponte rponte

🏠
Working from home
View GitHub Profile
@wpivotto
wpivotto / PreventExternalAccess.java
Created October 25, 2011 14:50
Tasks (Quartz Jobs) and Request Scope
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface PreventExternalAccess {
}
package br.com.foo.web.filters;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@wpivotto
wpivotto / MailController.java
Created October 28, 2011 13:18
Send a report via Email
import static br.com.caelum.vraptor.jasperreports.formats.ExportFormats.docx;
import static br.com.caelum.vraptor.jasperreports.formats.ExportFormats.pdf;
import static br.com.caelum.vraptor.jasperreports.formats.ExportFormats.xls;
import app.mailer.ReportEmail;
import app.mailer.ReportMailer;
import app.reports.ClientsReport;
import app.repositories.ClientRepository;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import static com.google.common.base.Objects.firstNonNull;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

Here's how to install PostgreSQL and have it run automatically at startup, on an Ubuntu 10.04 virtual machine using Vagrant. This took me a while to figure out:

Add the default lucid32 base box to your vagrant, if you haven't already:

host> vagrant box add lucid32 http://files.vagrantup.com/lucid32.box 

Now make a new lucid32 virtual machine and install postgresql on it:

@bhollis
bhollis / .htaccess
Created March 25, 2012 22:58
Serving pre-gzipped assets from Apache
AddEncoding gzip .gz
RewriteEngine on
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Konqueror
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)\.css$ $1.css.gz [QSA,L]
RewriteRule ^(.*)\.js$ $1.js.gz [QSA,L]
RewriteRule ^(.*)\.html$ $1.html.gz [QSA,L]
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@sauloarruda
sauloarruda / 1. README.md
Created April 17, 2012 19:01
Configurando aplicação Rails com Nginx e Unicorn

Configurando aplicação Rails com Nginx e Unicorn

TL;DR Como configurar uma aplicação Rails usando Nginx + Unicorn + Upstart + RVM (gemset por aplicação).

Dependências: (TODO) Configuração de Servidor Nginx

Essas instruções são aplicáveis para o seguinte ambiente:

  • Sistema Operacional: Ubuntu Server 12.04 beta2
  • Servidor: AWS EC2 usando ESB AMI: ubuntu/images-milestone/ebs/ubuntu-precise-12.04-beta2-amd64-server-20120328 (ami-b5ea34dc)
@lucascs
lucascs / DateAndTimeCalendarConverter.java
Created April 27, 2012 18:08
Calendar converter for date and time
@Convert(Calendar.class)
public class DateAndTimeCalendarConverter extends LocaleBasedCalendarConverter {
private final Localization localization;
public DateAndTimeCalendarConverter(Localization localization) {
super(localization);
this.localization = localization;
}
public Calendar convert(String value, Class<? extends Calendar> type, ResourceBundle bundle) {
if (Strings.nullToEmpty(value).length() > "dd/mm/yyyy".length()) {
public List<Movimentacao> listaTodasMovimentacoes(Conta conta) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Movimentacao> criteria = cb.createQuery(Movimentacao.class);
Root<Movimentacao> movimentacao = criteria.from(Movimentacao.class);
criteria.where(cb.equal(movimentacao.get(Movimentacao_.conta), conta))
.orderBy(cb.desc(movimentacao.get(Movimentacao_.valor)));
return em.createQuery(criteria).getResultList();
}