Skip to content

Instantly share code, notes, and snippets.

View thiagofa's full-sized avatar

Thiago Faria de Andrade thiagofa

View GitHub Profile
@thiagofa
thiagofa / mov2mp4_algaworks.py
Created September 25, 2012 01:36
Script em Python para converter screencasts (MOV para MP4) dos cursos online e incluir logo da AlgaWorks
import os
from os.path import *
import fnmatch
import sys
import commands
def is_success(result):
return result[0] == 0
def get_message(result):
@thiagofa
thiagofa / A.java
Created May 24, 2014 05:23
OneToOne com lazy
@Entity
public class A implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private B b;
@Id
@thiagofa
thiagofa / A.java
Created May 24, 2014 19:48
Lazy OneToOne with bytecode instrumentation
@OneToOne(optional = true, fetch = FetchType.LAZY)
public B getB() {
return b;
}
@thiagofa
thiagofa / primefaces-calendar-pt.js
Created February 23, 2016 14:04
Tradução do componente p:calendar para Português
PrimeFaces.locales['pt'] = {
closeText: 'Fechar',
prevText: 'Anterior',
nextText: 'Próximo',
currentText: 'Começo',
monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun', 'Jul','Ago','Set','Out','Nov','Dez'],
dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado'],
dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb'],
dayNamesMin: ['D','S','T','Q','Q','S','S'],
@thiagofa
thiagofa / Menu.xhtml
Created February 26, 2016 16:59
Como fazer com que o menu lateral do layout da AlgaWorks fique com o item selecionado, ao navegar para outra página?
<li class="#{menuBean.getItemCssClass('PesquisaClientes')}">
<h:link><i class="fa fa-fw fa-user"></i>Clientes</h:link>
</li>
<li class="#{menuBean.getItemCssClass('Relatorios')}">
<h:link><i class="fa fa-fw fa-file-text"></i>Relatórios</h:link>
</li>
@thiagofa
thiagofa / orm.xml
Created September 19, 2019 01:42
XML de mapeamento do JPA
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/orm_2_2.xsd"
version="2.2">
</entity-mappings>
@thiagofa
thiagofa / DatabaseCleaner.java
Last active October 6, 2024 23:35
Componente Spring para limpar os dados de todas as tabelas de um banco de teste (exceto a tabela de histórico do Flyway)
// Baseado em: https://brightinventions.pl/blog/clear-database-in-spring-boot-tests/
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
@thiagofa
thiagofa / ResourceUtils.java
Created October 17, 2019 20:52
Classe utilitária que retorna a string do conteúdo de um arquivo (recurso) do classpath
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import org.springframework.util.StreamUtils;
public class ResourceUtils {
public static String getContentFromResource(String resourceName) {
try {
@thiagofa
thiagofa / TomcatCustomizer.java
Created October 30, 2019 21:08
Customiza Tomcat embedado do Spring Boot para aceitar colchetes nas URLs
// Referências:
// - https://stackoverflow.com/a/53613678
// - https://tomcat.apache.org/tomcat-8.5-doc/config/http.html
// - https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-configure-webserver
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;
@Component
@thiagofa
thiagofa / HalCustomMediaTypeEnabler.java
Created December 15, 2019 00:48
Resolve o problema de custom media types com Spring HATEOAS (com formato HAL)
import java.util.Arrays;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;