Skip to content

Instantly share code, notes, and snippets.

View AntonioHReyes's full-sized avatar

Antonio Huerta Reyes AntonioHReyes

View GitHub Profile
@AntonioHReyes
AntonioHReyes / recursividad.java
Last active March 6, 2024 16:24
Recursividad Key
public class EjemplosRecursivosEIterativos {
// Calcular el factorial de un número de forma recursiva
// Recursivo significa que la función se llama a sí misma para resolver el problema
public static int factorialRecursivo(int n) {
if (n == 0) return 1; // Si n es 0, el resultado es 1 (como decir, 1 es el primer número para contar)
// Si no, multiplicamos n por el factorial del número anterior, hasta llegar a 1.
return n * factorialRecursivo(n - 1);
}
@AntonioHReyes
AntonioHReyes / authenticator-api-interceptor.ts
Last active June 18, 2023 22:34
Improved version: we fix the access token incorrect bug
import {Injectable, Injector} from "@angular/core";
import {HttpClient, HttpEvent, HttpHandler, HttpHeaders, HttpInterceptor, HttpRequest} from "@angular/common/http";
import {BehaviorSubject, Observable} from "rxjs";
import {EnvironmentService} from "../environment.service";
import {UserApplicationService} from "../services/user-application.service";
import {filter, switchMap, take} from "rxjs/operators";
import {AppStorageService} from "../services/app-storage.service";
import {AccessAndRefreshToken} from "../shared/providers/authenticator-api/interfaces/authenticator-api-interfaces";
@Injectable()
@AntonioHReyes
AntonioHReyes / asyncKotlin.kt
Created January 21, 2022 21:37
Async work with kotlin coroutines
fun main() = runBlocking{
//With async this job take 3 seconds
val firstValue = async { validate1() }
val secondValue = async { validate2() }
println("${firstValue.await()} ${secondValue.await()}")
//Without this job take 6 seconds
@AntonioHReyes
AntonioHReyes / setTimeout.kt
Last active December 4, 2021 20:27
SetTimeout Extension Function for Android
fun setTimeOut(handleFunction: () -> Unit, delay: Long): CountDownTimer {
val timer = object: CountDownTimer(delay, 1000){
override fun onFinish() {
CoroutineScope(Dispatchers.Main).launch {
handleFunction()
cancel()
}
}
@AntonioHReyes
AntonioHReyes / formatNumber.js
Created August 31, 2021 16:01
Función para formatear la entrada de un número telefónico
function formatPhoneNumber(phoneNumberString) {
var cleaned = ('' + phoneNumberString).replace(/\D/g, '');
var match = cleaned.match(/^(\d{1}|\d{2}|\d{3}|)?(\d{3})(\d{3})(\d{4})$/);
if (match) {
var intlCode = (match[1] ? `+${match[1]} ` : '');
return [intlCode, '(', match[2], ') ', match[3], '-', match[4]].join('');
}