Skip to content

Instantly share code, notes, and snippets.

View eduardobape's full-sized avatar
🤖

EduDev eduardobape

🤖
  • Spain
  • 04:00 (UTC +02:00)
View GitHub Profile
@eduardobape
eduardobape / FilterListByType.kt
Last active November 22, 2022 01:22
Two different methods implementations for filtering elements of a list by a specific type (or class)
fun main() {
println(filterByType1<Boolean>(listOf(1, 2, "hola", true)))
println(listOf(1, 2, 3, "hola", false).filterIsInstance<Boolean>())
println(filterByType2(listOf(10, 20, true, 10.5, "hello"), java.lang.Boolean::class.java))
println(filterByType2(listOf(10, 20, true, 10.5, "hello", false), Boolean::class.javaObjectType))
}
@Suppress("UNCHECKED_CAST")
inline fun <reified T> filterByType1(unfilteredList: List<*>): List<T> = unfilteredList.filter { it is T } as List<T>
@eduardobape
eduardobape / permissions.kt
Created August 9, 2022 18:17
Permissions flow for all Android versions using Activity Result APIs
package com.edudev.livedataroomexample
import android.Manifest
import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
@eduardobape
eduardobape / dagger-hilt-android-dependencies.md
Last active May 5, 2022 14:59
How to add gradle plugins and dependencies to include dagger-hilt to an Android project using Android Studio BumBlebee 2021.1.1 version or higher

File build.gradle (project):

buildscript {
    ext {
        daggerHiltVersion = '2.41'
    }
}
plugins {
    id 'com.google.dagger.hilt.android' version "$daggerHiltVersion" apply false
}
@eduardobape
eduardobape / diagonals.kt
Last active May 1, 2022 19:15
Get all diagonals of a matrix
// Displays the coordinates of all elements of the secondary diagonal and of all diagonals parallel to the secondary diagonal
fun printSecondaryDiagonals(numColumns: Int, numRows: Int) {
val diagonal = mutableListOf<Pair<Int, Int>>()
for (k in 0..numColumns + numRows - 2) {
for (j in 0..k) {
val i = k - j
if (i < numRows && j < numColumns) {
diagonal.add(Pair(i, j))
}
}
import java.math.BigDecimal
import java.math.RoundingMode
import kotlin.math.pow
const val EXIT = "/exit"
const val BACK = "/back"
const val BASE_10 = 10
const val MAX_LENGTH_FRACTIONAL_PART = 5
const val FRACTIONAL_PART_DELIMITER = '.'
@eduardobape
eduardobape / .gitignore
Last active May 1, 2022 18:59
.gitignore file for a common Android project
#built application files
*.apk
*.ap_
*.aab
# files for the dex VM
*.dex
# Java class files
*.class
@eduardobape
eduardobape / setup_ssh_git_and_github.md
Last active April 7, 2023 12:14
How to configure SSH for Git and Github using a SSH key with a custom name file

Configuración Git y GitHub mediante SSH en Windows

Abrir la consola GitBash

Abrir la consola Git Bash.

Configuración inicial de Git (sólo para un repositorio en concreto)

Navegar hasta el directorio donde se encuentra el repositorio e introducir los siguientes comandos para especificar el nombre y dirección de correo electrónico que se usarán en cada commit:

git config --local user.name "Mi nombre"