Skip to content

Instantly share code, notes, and snippets.

View fabriciofx's full-sized avatar
🎯
Focusing

Fabrício Cabral fabriciofx

🎯
Focusing
  • Brazil
  • 00:59 (UTC -03:00)
View GitHub Profile
#don't send the nginx version number in error pages and Server header
server_tokens off;
# config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
# to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
# config to don't allow the browser to render the page inside an frame or iframe
# and avoid clickjacking http://en.wikipedia.org/wiki/Clickjacking
# if you need to allow [i]frames, you can use SAMEORIGIN or even set an uri with ALLOW-FROM uri
@Component
public class Carro {
private Motor motor;
@Autowired
public Carro(@Qualifier("motorAGasolina") Motor motor) {
this.motor = motor;
}
java -jar war/WEB-INF/lib/htmlcompressor-*.jar \
--type html --recursive --mask '*.jsp;*.html;*.tag;*.htm' \
--compress-css --compress-js --js-compressor closure \
--remove-intertag-spaces --remove-quotes \
--preserve-server-script -p regex.txt \
-o war/ war/ 2> /dev/null
/*
|--------------------------------------------------------------------------
| Delete form macro
|--------------------------------------------------------------------------
|
| This macro creates a form with only a submit button.
| We'll use it to generate forms that will post to a certain url with the DELETE method,
| following REST principles.
|
*/
package icob.model.entity.converter;
import java.sql.Timestamp;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import org.joda.time.LocalDateTime;
@Converter(autoApply = true)
@fabriciofx
fabriciofx / MontyHall.java
Created May 24, 2014 16:24
Simulador para o problema do Monty Hall
package exemplos;
import java.util.Random;
public class MontyHall {
// Dadas duas portas, escolhe aquela que restou.
// Exemplos:
// se forem dadas as portas 0 e 1, retorna 2
// se forem dadas as portas 0 e 2, retorna 1
// se forem dadas duas portas iguais (0 e 0, por ex.) retorna a primeira livre,
package fx.time;
import java.sql.Date;
import java.time.LocalDate;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter(autoApply = true)
public class PersistentLocalDate implements AttributeConverter<LocalDate, Date> {
package foo.model.repository;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.AfterClass;
import org.junit.BeforeClass;
public abstract class AbstractRepositoryTest {
@fabriciofx
fabriciofx / ValidaCPF.java
Created December 16, 2014 20:50
Código para validar o CPF de pessoa física
public static boolean valida(String numero) {
if (numero == null || !numero.matches("^[0-9]{11}$")) {
throw new IllegalArgumentException("número de CPF inválido!");
}
int dv1, dv2;
int num[] = new int[11];
for (int i = 0; i < num.length; i++) {
char c = numero.charAt(i);
import java.util.Arrays;
public class Capitalize {
public static String capitalize (String x) {
return x.substring(0,1).toUpperCase() + x.substring(1).toLowerCase();
}
public static void main(String[] args) {
String text = "gabinete do deputado fulando de tal e de dona maria";