Skip to content

Instantly share code, notes, and snippets.

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

Ángel Quiroz AngelAlexQC

🏠
Working from home
View GitHub Profile
@AngelAlexQC
AngelAlexQC / useLocalStorage.js
Created August 9, 2022 17:13
Use global state with localStorage, sync between tabs
import { useEffect, useState } from "react";
const useLocalStorage = (key, initialValue) => {
// State to store our value
// Pass initial state function to useState so logic is only executed once
const [storedValue, setStoredValue] = useState(() => {
if (typeof window === "undefined") {
return initialValue;
}
try {
@AngelAlexQC
AngelAlexQC / filter.pipe.ts
Created May 24, 2022 13:26
Angular Filter pipe
import { Pipe, PipeTransform, Injectable } from '@angular/core';
@Pipe({
name: 'filter'
})
@Injectable()
export class FilterPipe implements PipeTransform {
transform(items: any, filter: any, defaultFilter: boolean = true): any {
if (!filter) {
return items;
@AngelAlexQC
AngelAlexQC / countries.ts
Created November 19, 2021 22:36
Countries List
export const countries = [
"Ecuador",
"Afganistan",
"Albania",
"Alemania",
"Andorra",
"Angola",
"Antartida",
"Antigua y Barbuda",
"Arabia Saudi",
@AngelAlexQC
AngelAlexQC / error-interceptor.ts
Last active October 15, 2021 00:46
Interceptor for 401 errors
import { AuthService } from './../services/auth.service';
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
@AngelAlexQC
AngelAlexQC / Factura-Preview.php
Created October 9, 2021 22:29
Factura SRI Ecuador para firmar
<?php
namespace App\Models;
use Carbon\Carbon;
use DOMDocument;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use RobRichards\XMLSecLibs\XMLSecurityDSig;
use RobRichards\XMLSecLibs\XMLSecurityKey;
@AngelAlexQC
AngelAlexQC / validarCedula.ts
Created October 2, 2021 19:23
Validar Cédulas en Ecuador (Error First).
export function cedulaValida(cedula: string): boolean {
if (cedula.length != 10) return false;
// Digitos de provincia (2 primeros)
const digitos_provincia = cedula.substring(0, 2);
// Deben estar entre 1 y 24.
if (parseInt(digitos_provincia) < 1 || parseInt(digitos_provincia) > 24)
return false;
// Coeficientes de validación (en posiciones pares)
const coeficientes = [2, 1, 2, 1, 2, 1, 2, 1, 2];
// Obtener la suma de multiplicar los dígitos por su respectivo coeficiente, si el resultado es mayor que 9, se resta 9.
@AngelAlexQC
AngelAlexQC / create_angular_project.sh
Last active August 13, 2021 02:06
Crear proyecto de Angular
#!/bin/bash
ng new pickup-client -S --commit=true --inline-style=false --inline-template=false --minimal=true --routing=true --style=scss
@AngelAlexQC
AngelAlexQC / functions.ts
Created January 18, 2021 19:42
Validar Cédula "Ecuador"
export function validarCedula(cedula: string | any) {
let total = 0;
const longitud = cedula.length;
const longcheck = longitud - 1;
if (cedula !== "" && longitud === 10) {
for (let i = 0; i < longcheck; i++) {
if (i % 2 === 0) {
let aux = cedula.charAt(i) * 2;
if (aux > 9) {