Skip to content

Instantly share code, notes, and snippets.

View gorrotowi's full-sized avatar
🏠
Working from home

sebastian tellez gorrotowi

🏠
Working from home
View GitHub Profile
@gorrotowi
gorrotowi / SafeCoroutineWException.kt
Created March 31, 2022 22:33
ViewModel with a function which handle the coroutine exception
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.flux.mobile.utils.loge
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
@gorrotowi
gorrotowi / AdapterProducts.kt
Last active December 14, 2019 21:01
FirebaseWorkshop
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.gorrotowi.firebaseworkshop.R
import com.gorrotowi.firebaseworkshop.entities.FirebaseProduct
import kotlinx.android.synthetic.main.item_product.view.*
import kotlin.properties.Delegates
class AdapterProducts : RecyclerView.Adapter<AdapterProducts.ProducsViewHolder>() {

Keybase proof

I hereby claim:

  • I am gorrotowi on github.
  • I am gorrotowi (https://keybase.io/gorrotowi) on keybase.
  • I have a public key ASDLdGLEHxY9unTMiueFG7WU0M331hjgX4vMUFcxw5KXdwo

To claim this, I am signing this object:

@gorrotowi
gorrotowi / act.kt
Last active April 20, 2019 19:08
Color hex kotlin function
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
when (resultCode) {
Activity.RESULT_OK -> {
val place = data?.let { Autocomplete.getPlaceFromIntent(it) }
Log.e("PlaceResult", "${place?.toString()}")
}
Activity.RESULT_CANCELED -> {
Log.e("PlaceCanceled", "No Place selected")
val name:String? = null
var length:Int
if(name != null){
length = name.length
} else{
length = -1
}
print(length) // -1
@gorrotowi
gorrotowi / elvisoperatorsample.kt
Created July 26, 2018 00:25
Use elvis operator instead if/else
val name:String? = null
val l:Int = name?.length ?: -1
print(l) // -1
@gorrotowi
gorrotowi / ifnotnull.kt
Created July 26, 2018 00:16
Use data if objects is not null
val name:String? = null
val l:Int = if(name != null) name.length else -1
print(l) // -1
@gorrotowi
gorrotowi / alphaHexColor.kt
Last active January 5, 2018 21:29
How to set Alpha for HexColor
import kotlin.math.roundToInt
fun main(args: Array<String>) {
println("#2c79a5".alphaColor(0.5F))
println(getColorIntWithAlpha("#2c79a5",0.5F))
}
fun getColorIntWithAlpha(hexColor: String, alpha: Float): Int =
Color.parseColor(hexColor.alphaColor(alpha))
@gorrotowi
gorrotowi / bplanet.kt
Last active December 13, 2017 18:20
bplanet
import java.io.File
import java.io.InputStream
import kotlin.math.sqrt
fun main(args: Array<String>) {
val inputStream: InputStream = File("src/test_case.txt").inputStream()
val lineList = mutableListOf<String>()
inputStream.bufferedReader().useLines { lines ->
@gorrotowi
gorrotowi / Galleta.kt
Created October 12, 2017 16:43
Platzi POJO Java vs Kotlin
data class Galleta(val sabor: String, val chispas: String)