Skip to content

Instantly share code, notes, and snippets.

View alexandreaquiles's full-sized avatar

Alexandre Aquiles alexandreaquiles

View GitHub Profile
package br.com.paradizo.tema;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.*;
import java.util.Collections;
public class FileUtils {
public class FileUtils {
public static String getResourceContents(String resource) throws URISyntaxException, IOException {
Path resourcePath = getResourceAsPath(resource);
return getPathContents(resourcePath);
}
private static Path getResourceAsPath(String resource) throws URISyntaxException, IOException {
URI uri = FileUtils.class.getResource(resource).toURI();
@Configuration
public class JacksonConfig {
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
@alexandreaquiles
alexandreaquiles / .bashrc
Created March 21, 2018 16:13
show current SDK Java version on the command prompt
#show java version on prompt
current_sdk_java_version() {
export PS1="\e[0;32m$(sdk current java version | grep version | sed -e 's/.*version \(.*\)/\1/')\e[m$ "
}
PROMPT_COMMAND="current_sdk_java_version"
@alexandreaquiles
alexandreaquiles / EscapeXmlELResolverListener.java
Last active May 7, 2020 07:19
EscapeXmlELResolverListener for Spring Boot based on pukkaone.github.io/2011/01/03/jsp-cross-site-scripting-elresolver.html
package br.com.caelum.fj91.seguranca;
import java.beans.FeatureDescriptor;
import java.util.Iterator;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.jsp.JspContext;
@alexandreaquiles
alexandreaquiles / show-module-resolution.txt
Last active November 30, 2017 14:13
Result of 'java --show-module-resolution' the unnamed module for Oracle JDK 9 (build 9.0.1+11)
root jdk.management.jfr jrt:/jdk.management.jfr
root jdk.jdi jrt:/jdk.jdi
root javafx.web jrt:/javafx.web
root jdk.xml.dom jrt:/jdk.xml.dom
root jdk.jfr jrt:/jdk.jfr
root jdk.packager.services jrt:/jdk.packager.services
root jdk.httpserver jrt:/jdk.httpserver
root javafx.base jrt:/javafx.base
root jdk.net jrt:/jdk.net
root javafx.controls jrt:/javafx.controls
@alexandreaquiles
alexandreaquiles / 2017-11-22.log
Created November 22, 2017 11:25
Warning when _ used as an identifier in Java 8. Compilation error in Java 9 (though, bytecode from Java 8 is executed).
alexandre ~/keyword $ /usr/lib/jvm/java-8-oracle/bin/javac Keyword.java
Keyword.java:3: warning: '_' used as an identifier
int _ = 1;
^
(use of '_' as an identifier might not be supported in releases after Java SE 8)
Keyword.java:4: warning: '_' used as an identifier
System.out.println(_);
^
(use of '_' as an identifier might not be supported in releases after Java SE 8)
2 warnings
@alexandreaquiles
alexandreaquiles / MedicaoDeTempoFilter.java
Created November 17, 2017 16:18
Filter para medição de tempo
package br.com.caelum.tarefas.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;
@alexandreaquiles
alexandreaquiles / github.gql
Created August 28, 2017 16:32
Consulta GraphQL que busca estatísticas do projeto Express: o número de stars, de pull requests abertos, de issues abertas, a data da última release e informações do último commit.
query {
repository(owner:"expressjs", name: "express") {
stargazers {
totalCount
}
pullRequests(states: OPEN) {
totalCount
}
issues(states:OPEN) {
totalCount
class A {
static int x() {
return 1;
}
}
class B extends A {
static int x() {
return 2;
}
}