Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Lex AngelAlexQC

🏠
Working from home
View GitHub Profile
@AngelAlexQC
AngelAlexQC / useLocalStorage.js
Created Aug 9, 2022
Use global state with localStorage, sync between tabs
View useLocalStorage.js
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
Angular Filter pipe
View filter.pipe.ts
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;
View countries.ts
export const countries = [
"Ecuador",
"Afganistan",
"Albania",
"Alemania",
"Andorra",
"Angola",
"Antartida",
"Antigua y Barbuda",
"Arabia Saudi",
@AngelAlexQC
AngelAlexQC / error-interceptor.ts
Last active Oct 15, 2021
Interceptor for 401 errors
View error-interceptor.ts
import { AuthService } from './../services/auth.service';
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
@AngelAlexQC
AngelAlexQC / Factura-Preview.php
Created Oct 9, 2021
Factura SRI Ecuador para firmar
View Factura-Preview.php
<?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 Oct 2, 2021
Validar Cédulas en Ecuador (Error First).
View validarCedula.ts
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 Aug 13, 2021
Crear proyecto de Angular
View create_angular_project.sh
#!/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 Jan 18, 2021
Validar Cédula "Ecuador"
View functions.ts
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) {