Skip to content

Instantly share code, notes, and snippets.

View leoallvez's full-sized avatar
🎯
Focusing

Leonardo Alves leoallvez

🎯
Focusing
View GitHub Profile
@leoallvez
leoallvez / firebase.dart
Last active June 24, 2020 00:49
Exemplos de leitura e escrita com firestore e flutter
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main() async {
runApp(MyApp());
//Escrevendo dados na base de dados.
//OBS: se o parametro de document() for vazio é criado um id para
// o documento de forma automática.
Firestore.instance.collection("mensagens").document().setData({
@leoallvez
leoallvez / BasicCoroutinesFlow.kt
Created February 6, 2020 03:28
Basic coroutines flow
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.runBlocking
/**
flow {...} - build
emit(value) - transmit a value
collect {...} - receive the values
@leoallvez
leoallvez / BaseService.kt
Last active February 4, 2020 17:32
ServiceExemple
import android.app.IntentService
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.util.Log
import androidx.core.content.edit
import com.google.gson.Gson
abstract class BaseService(val name: String) : IntentService(name) {
val verdadeiro = true
val falso = false
val resultado1 = verdadeiro.and(falso) //resultado1 = false
val resultado2 = verdadeiro.or(falso) //resultado2 = true
val resultado3 = verdadeiro.not() //resultado3 = false
val resultado4 = verdadeiro.xor(falso) //resultado4 = true
println("$resultado1, $resultado2, $resultado3, $resultado4")
fun check(c: Char) {
if (c == 1) { //ERRO: tipos incompatíveis
// ...
}
}
val i: Int = b.toInt() // OK: covertido explicitamente.
print(i)
// Código hipotético, na verdade não compila:
val a: Int? = 1 // Tipo Int (java.lang.Integer)
val b: Long? = a // conversão implícita produz um Long (java.lang.Long)
print (b == a) // Surpresa! Isso imprime "falso"
@leoallvez
leoallvez / underscores_in_numeric.kt
Last active May 22, 2019 02:47
Underscores in numeric
val umMilhao = 1_000_000
val numeroCartaoCredito = 1234_5678_9012_3456L
val numeroSeguroSocial = 999_99_9999L
val hexBytes = 0xFF_EC_DE_5E
val bytes = 0b11010010_01101001_10010100_10010010
val s = "abc"
val str ="$s.length is ${s.length}"
println(str) // imprime "abc.length is 3"
val inteiro = 10
val resultado = "inteiro = $inteiro"
print(resultado) // imprime "inteiro = 10"