Skip to content

Instantly share code, notes, and snippets.

View luizjacomn's full-sized avatar
🎯
Focusing

Luiz Jacó luizjacomn

🎯
Focusing
View GitHub Profile
@luizjacomn
luizjacomn / main.dart
Last active June 10, 2019 11:35
Testando relação entre categoria e itens
void main(){
Categoria cat1 = Categoria(1);
List<Item> itens = [
Item(id: 1, completado: false, obrigatorio: false),
Item(id: 2, completado: true, obrigatorio: true),
Item(id: 3, completado: true, obrigatorio: true),
Item(id: 4, completado: true, obrigatorio: false),
Item(id: 5, completado: true, obrigatorio: true),
];
cat1.itens = itens;
@luizjacomn
luizjacomn / main.dart
Created June 10, 2019 11:34
Diferença entre durations em Dart
void main() {
Duration duration = Duration(minutes: 1, seconds: 10);
int d1 = duration.inMicroseconds;
Duration duration2 = Duration(minutes: 2, seconds: 25);
int d2 = duration2.inMicroseconds;
print('$duration -> $d1');
print('$duration2 -> $d2');
int diff = d2-d1;
Duration duration3 = Duration(microseconds: diff);
print('$duration3 -> $diff');
import 'dart:async';
void main() {
List convidados = ['Daniel', 'João', 'Marcos', 'Jessica', 'Natalia'];
final controller = StreamController();
final subscription = controller.stream
.where((conv) => convidados.contains(conv))
.listen((data) => print(data));
@luizjacomn
luizjacomn / main.dart
Created July 4, 2019 12:55
Print int if double number no has decimal places
void main() {
double num = 1.5;
//double num = 1.0;
print((num % 1) == 0 ? num.toInt() : num);
}
@luizjacomn
luizjacomn / RedirectView.java
Created August 8, 2019 18:08
Encapsulando o redirecionamento de views JSF
public class RedirectView {
private String viewName;
public RedirectView(String viewName) {
this.viewName = viewName;
}
@Override
public String toString() {
return viewName + "?faces-redirect=true";
@luizjacomn
luizjacomn / CloneUtil.java
Created August 12, 2019 18:27
Clone serializable object (allows modify properties without affects the original one).
public <T extends Serializable> T clone(Serializable obj) {
ObjectOutputStream out = null;
ObjectInputStream in = null;
try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
out = new ObjectOutputStream(bout);
out.writeObject(obj);
out.close();
@luizjacomn
luizjacomn / CloneUtil.java
Created August 12, 2019 18:35
Clone object using Jackson's library (allows modify properties without affects the original one).
public <T> T clone(Object obj, Class<T> clazz) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.readValue(objectMapper.writeValueAsString(obj), clazz);
} catch (IOException e) {
throw new Exception();
}
}
extension on String {
String concat(String toConcat) => this + toConcat;
}
main() {
String test = 'primeira';
String expected = test.concat(' e segunda');
assert('primeira e segunda' == expected);
print(expected);
void main() {
// criando variável teste.
String teste = 'teste';
// "printa" 5 no console.
print(teste.length);
// setando valor para null.
teste = null;
// caso tente acessar a variável diretamente esta estando nula, uma exceção é lançada.
// com o operador ?. isso é evitado pois a variável teste somente é acessada quando seu valor for diferente de nulo.
print(teste?.length);
void main() {
Imposto icms = ICMS();
Imposto iptu = IPTU();
CalculoImposto calc = CalculoImposto();
print(calc.calcularImposto(icms, 100));
print(calc.calcularImposto(iptu, 50));
}