Skip to content

Instantly share code, notes, and snippets.

View Gnzlt's full-sized avatar

Gonzalo Toledano Gnzlt

View GitHub Profile
@Gnzlt
Gnzlt / InpsectionPermissionState.kt
Last active September 17, 2023 22:25
Jetpack Compose extension function to show Previews when using permission checks
package com.example
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalInspectionMode
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.PermissionState
import com.google.accompanist.permissions.PermissionStatus
/**
* Wrapper for [com.google.accompanist.permissions.rememberPermissionState] to grant permissions when in Inspection mode
@Gnzlt
Gnzlt / CameraPreview.kt
Last active August 21, 2023 22:18
Android Jetpack Compose Camera Preview Composable
@Composable
fun CameraPreview(
modifier: Modifier = Modifier,
scaleType: PreviewView.ScaleType = PreviewView.ScaleType.FILL_CENTER,
cameraSelector: CameraSelector = CameraSelector.DEFAULT_FRONT_CAMERA
) {
val lifecycleOwner = LocalLifecycleOwner.current
AndroidView(
modifier = modifier,
factory = { context ->
@Gnzlt
Gnzlt / upload_video.py
Created August 20, 2023 09:43
Python 3 script that uploads a YouTube video using the YouTube Data API
#!/usr/bin/python
import http.client
import httplib2
import os
import random
import sys
import time
from apiclient.discovery import build
@Gnzlt
Gnzlt / NfcUtils.kt
Created January 17, 2022 20:00
Android NFC MIFARE Classic utils
package com.example
import android.content.Context
import android.nfc.tech.MifareClassic
object NfcUtils {
fun Context.isMifareClassicCompatible(): Boolean =
packageManager.systemAvailableFeatures.any { it.name == "com.nxp.mifare" }
@Gnzlt
Gnzlt / NfcTagLifecycleObserver.kt
Created January 15, 2022 23:17
Android NFC Tag Lifecycle Observer
package com.example
import android.app.Activity
import android.nfc.NfcAdapter
import android.nfc.Tag
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
class NfcTagLifecycleObserver(
private val activity: Activity,
@Gnzlt
Gnzlt / HashCompositeDisposable.kt
Last active January 4, 2022 12:26
RxJava Disposable that can hold onto multiple other Disposables and only keeps the last Disposable added with the same key.
package com.example
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.exceptions.CompositeException
import io.reactivex.rxjava3.exceptions.Exceptions
import io.reactivex.rxjava3.internal.util.ExceptionHelper
/**
* A disposable that can hold onto multiple other Disposables
* and only keeps the last Disposable added with the same key.
@Gnzlt
Gnzlt / SuffixTextInputEditText.kt
Last active March 8, 2021 10:03
TextInputEditText with support for non editable suffix.
package com.example
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.Typeface
import android.text.TextPaint
import android.util.AttributeSet
import com.google.android.material.textfield.TextInputEditText
@Gnzlt
Gnzlt / YuvImageDataFetcher.kt
Last active September 26, 2020 10:22
Custom Glide ModelLoader for Yuv Image [YUV_420_888]
import android.graphics.ImageFormat
import android.graphics.Rect
import android.graphics.YuvImage
import android.media.Image
import com.bumptech.glide.Priority
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.data.DataFetcher
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer
@Gnzlt
Gnzlt / OffsetPageTransformer.kt
Last active August 30, 2024 03:05
Android ViewPager2 PageTransformer to show multiple pages at the same time
package com.example
import android.view.View
import android.view.ViewGroup
import androidx.annotation.Px
import androidx.core.view.ViewCompat
import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
@Gnzlt
Gnzlt / ViewPagerUtils.kt
Last active September 11, 2020 10:17
Android ViewPager2 extension function to scroll to the last position
package com.example.utils
import androidx.viewpager2.widget.ViewPager2
object ViewPagerUtils {
fun ViewPager2.scrollToLastPosition() {
val lastPosition = adapter?.itemCount?.minus(1) ?: 0
if (currentItem != lastPosition) {
currentItem = lastPosition