Skip to content

Instantly share code, notes, and snippets.

View filiperdt's full-sized avatar

Rúben Filipe Andrade de Oliveira filiperdt

View GitHub Profile
@filiperdt
filiperdt / printConsole.html
Created April 29, 2021 22:56
Print Thymeleaf variable in console.log
<script th:inline="javascript">
/*<![CDATA[*/
console.log(/*[[${myVariable.id}]]*/ 'default');
/*]]>*/
</script>
@filiperdt
filiperdt / printEnum.java
Created May 5, 2021 18:31
Enum function to print values ​​with the first capital letter
@Override
public String toString() {
return Character.toUpperCase(name().charAt(0)) + name().toLowerCase().substring(1);
}
@filiperdt
filiperdt / index.html
Created May 5, 2021 21:55
Minimum page Thymeleaf and Bootstrap
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<title>Thymeleaf and Bootstrap</title>
@filiperdt
filiperdt / form.html
Created May 18, 2021 19:50
Insert current date time into Thymeleaf input th:value
<input type="text" class="form-control" th:value="${#dates.format(#dates.createNow() , 'yyyy/MMM/dd_HH-mm-ss')}">
@filiperdt
filiperdt / forEachJava.java
Created June 17, 2021 16:58
Formas de for each no Java
// for each 1
for(Mensagem mensagem : mensagens){
System.out.println(mensagem);
}
// for each 2 - Utilizando função
mensagens.forEach(mensagem -> {
System.out.println(mensagem);
});
// for each 3
mensagens.forEach(System.out::println);
@filiperdt
filiperdt / sortArray.js
Last active July 24, 2021 18:11
Sort array by id with Array.sort() in JavaScript
items => {
items.sort((a, b) => a.id < b.id ? -1 : a.id === b.id ? 0 : 1);
// If you need your sort to work with accented characters use:
a.nome.localeCompare(b.nome)
// instead of
a.nome < b.nome ? // ...
@filiperdt
filiperdt / controller.java
Created July 25, 2021 02:18
Return enum in REST Spring
@GetMapping(value = "/foo")
@ResponseBody
public ResponseEntity<List<YourEnum>> listYourEnum() {
return new ResponseEntity<List<YourEnum>>(Arrays.asList(YourEnum.values()), HttpStatus.OK);
}
@filiperdt
filiperdt / Erro no Eclipse ao instalar o Lombok.txt
Created September 15, 2021 19:07
Erro no Eclipse ao instalar o Lombok, utilizando Java 11
Adicionar ao final do C:/eclipse/eclipse.ini:
--illegal-access=warn
--add-opens java.base/java.lang=ALL-UNNAMED
@filiperdt
filiperdt / listarConstraintsPostgreSQL.sql
Last active September 20, 2021 22:54
Listar todas as constraints, no PostgreSQL. Os resultados são ordenados por schema e table. A coluna "constraint_type" pode ser: p - chave primária, f - chave estrangeira, u - único, c - restrição de verificação, x - exclusão, ...
SELECT c.conname AS constraint_name,
c.contype AS constraint_type,
sch.nspname AS "self_schema",
tbl.relname AS "self_table",
ARRAY_AGG(col.attname ORDER BY u.attposition) AS "self_columns",
f_sch.nspname AS "foreign_schema",
f_tbl.relname AS "foreign_table",
ARRAY_AGG(f_col.attname ORDER BY f_u.attposition) AS "foreign_columns",
pg_get_constraintdef(c.oid) AS definition
FROM pg_constraint c
@filiperdt
filiperdt / javascriptEliminarRepeticaoObjectArray.js
Last active October 2, 2021 23:01
Eliminar repetição de registros no JavaScript, em um Object array, no ES6+
// Eliminar os exclusivos idem uma matriz
arr.filter((v,i,a)=>a.findIndex(t=>(t.id === v.id))===i)
// Eliminar por várias propriedades ( placee name)
arr.filter((v,i,a)=>a.findIndex(t=>(t.place === v.place && t.name===v.name))===i)
// Eliminar por todas as propriedades (isso será lento para matrizes grandes)
arr.filter((v,i,a)=>a.findIndex(t=>(JSON.stringify(t) === JSON.stringify(v)))===i)
// Manter a última ocorrência