Skip to content

Instantly share code, notes, and snippets.

View ElianFabian's full-sized avatar

Elián Fabián ElianFabian

View GitHub Profile
@ElianFabian
ElianFabian / CustomTimePicker.kt
Created September 10, 2025 08:54
Simple time picker with custom minute interval.
package packageName
import android.app.AlertDialog
import android.content.Context
import android.view.Gravity
import android.widget.LinearLayout
import android.widget.NumberPicker
import java.time.LocalTime
import kotlin.math.roundToInt
# PowerShell script to optimize the CPU usage to avoid doing it manually in the Windows Panel Control.
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole] "Administrator")) {
Write-Host "No eres administrador, reiniciando script con permisos elevados..." -ForegroundColor Yellow
$newProcess = Start-Process powershell "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs -PassThru
$newProcess.WaitForExit()
exit
}
@ElianFabian
ElianFabian / Ast.ps1
Last active July 16, 2025 14:48
Basic PowerShell to GlovePIE transpiler. For a better debugging experience with AST: https://github.com/lzybkr/ShowPSAst. For more information about GlovePIE: https://github.com/GlovePIEPreservation/GlovePIE/wiki.
<#
NOTES:
----- Something that we could do to make this more powerful would be to first transpile to a low level PowerShell code and then transpile to GlovePIE.
- Numeric types in GlovePIE are int32 and float, so we should use them instead of
other alternatives.
- When we wait inside an if, let's say it's the first line, it will not execute until
the rest of the code is executed or there is a wait.
- If an if has not finished due to a pending wait then the if will be ignored in that execution
- There's an 'int' function that seems to truncate float numbers (this does not convert strings to int).
- There's a 'float' that converts an int to float and convert strings to floats.
package yourpackage
import android.annotation.SuppressLint
import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.content.res.Resources
@ElianFabian
ElianFabian / ExtendedCardView.kt
Last active September 22, 2024 20:32
A CardView that allows setting the corner radius as a percentage. It also fix the issue of the corner radius exceeding the 50% limit on API 22 and below which causes the card to look weird.
package yourpackage
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.View
import androidx.cardview.widget.CardView
import yourpackage.R
/**
@ElianFabian
ElianFabian / LanguageContextWrapper.kt
Last active September 20, 2024 17:03
ContextWrapper to propperly update the locale of your application. The default implementation takes the first supported locale, otherwise takes the default locale.. Gist to generate the supported and default locale: Gist to generate the supported locales: https://gist.github.com/ElianFabian/e94071f348998c24bedaa959ddb8df40
import android.annotation.SuppressLint
import android.app.Application
import android.content.ComponentCallbacks
import android.content.Context
import android.content.ContextWrapper
import android.content.res.Configuration
import android.content.res.Resources
import android.os.Build
import android.os.LocaleList
import androidx.core.os.ConfigurationCompat
using System;
// From the Kotlin standard library
public class XorWowRandom
{
private int x, y, z, w, v, addend;
private XorWowRandom() { }
public static XorWowRandom FromSeed(int seed)
@ElianFabian
ElianFabian / PariGp.ps1
Created July 11, 2024 19:17
Example of how to use PARI/GP inside PowerShell
function Get-PrimeNumber([ulong] $position) {
return [System.UInt128] ("prime($position)" | gp.exe -q)
}
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.ViewGroup
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.DimenRes
import androidx.annotation.Dimension
import androidx.annotation.Px
import androidx.core.content.ContextCompat
@ElianFabian
ElianFabian / AsyncResource.kt
Last active September 30, 2024 19:26
Network utilities for Android.
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.sync.*
interface AsyncResource<out T> {
sealed interface State<out T> {
data object NotStarted : State<Nothing>
data class Loading<out T>(val currentResource: Completed<T>?) : State<T>
sealed interface Completed<out T> : State<T> {