Skip to content

Instantly share code, notes, and snippets.

View alexalannunes's full-sized avatar
👨‍💻
I'm coding

Alex Alan Nunes alexalannunes

👨‍💻
I'm coding
View GitHub Profile
@alexalannunes
alexalannunes / toSlug.ts
Created June 16, 2024 14:54
convert string to slug to use as url, id or other case
const REGEX_HELPER = {
ALL_NON_DOT_DIGITS: /[^0-9.-]+/g,
ALL_NON_NUMBERS: /\D+/g,
ANY_EACH_UPPERCASE_LETTER: /([A-Z])/g,
NUMBER_WITH_PX_SUFFIX: /(-?\d+)px/,
ONLY_ALLOWED_CHARACTERS: /^[A-Za-z0-9/;&\-_ ]+$/,
ONLY_ALPHANUMERIC_AND_SPECIAL_CHARS: /^[A-Za-z0-9/\-_@!#$% ]+$/,
ONLY_POSITIVE_DECIMAL: /^\d+(\.\d{0,2})?$/,
ONLY_POSITIVE_INTEGER_NUMBERS: /^\d+$/,
ONLY_POSITIVE_INTEGER_NUMBERS_WITHOUT_LEADING_ZERO: /^[1-9]\d*$/,
@alexalannunes
alexalannunes / extract_bills_from_nubank_pdf.js
Last active June 23, 2024 14:50
extract bills from nubank
`
15 MAI Picpay *Enel Distribu - Parcela 4/5 R$ 26,46
21 MAI Brisanet*Internet R$ 94,99
22 MAI Pagamento em 22 MAI -R$ 1.160,77
22 MAI Saldo restante da fatura anterior R$ 0,00
22 MAI Saldo restante da fatura anterior R$ 0,00
24 MAI Mercadinho e Hortifrut R$ 4,50
24 MAI Angela Maria Morais S R$ 14,36
24 MAI Mercantil Mundinho R$ 9,61
24 MAI Google Adobe Inc R$ 7,99
@alexalannunes
alexalannunes / index.ts
Created September 21, 2023 04:35
get difference between array of lines. Which fields are different
interface TableRow {
id: number,
fa: {
qty: number
},
fd: {
qty: number
},
ka: {
qty: number
@alexalannunes
alexalannunes / slice-array.js
Last active July 5, 2023 11:48
divide array
const a = [1,2,3,4,5,6,7,8]
const newarr=[]
const cols = 4
const interactions = a.length/cols
let index = 0
console.log(interactions)
for (let i = 0; i < interactions;i++) {
[alias]
s = !git status -s
c = !git add . && commit -m
l = !git log --pretty=format:'%C(blue)%h%C(red)%d %C(white)%s - %C(cyan)%cn, %C(green)%cr'
@alexalannunes
alexalannunes / array-intersection-diff-bi-diff.ts
Last active March 29, 2023 11:40
array intersection, diff, symmetrical difference
const a = [1,2,3]
const b = [1,4,5]
// using find instead includes
const inter = a.filter(x => b.find(x1 => x1 == x));
const diff = a.filter(x => !b.find(x1 => x1 == x));
const simtricDiff = a.filter(x => !b.find(x1 => x1 == x)).concat(b.filter(x => !a.find(x1 => x1 == x)));
inter // [ 1 ]
@alexalannunes
alexalannunes / react-infinite-query.tsx
Created February 23, 2023 14:15
exmaple with useInfiniteQuery & TypeScript
import { Button, Container } from "@chakra-ui/react";
import {
QueryClient,
QueryClientProvider,
useInfiniteQuery,
} from "@tanstack/react-query";
const client = new QueryClient();
const fetchProjects = async (skip: number): Promise<Response> => {
@alexalannunes
alexalannunes / use-case.md
Created December 27, 2022 23:48
caso de uso "Registro de curso" (demo) ou história de usuário

Título

Inscreva-se nos cursos

Descrição

O aluno acessa o sistema e visualiza os cursos atualmente disponíveis para ele se matricular. Em seguida, ele seleciona os cursos e se inscreve neles.

ator principal

@alexalannunes
alexalannunes / index.ts
Last active November 11, 2022 00:25
mock axios with react
import { fireEvent, render, screen } from "@testing-library/react";
import axios from "axios";
import { getUser } from "./api";
import App from "./App";
jest.mock("axios");
const api = axios as jest.Mocked<typeof axios>;
// app.test.tsx
test("renders learn react link", async () => {
@alexalannunes
alexalannunes / index.js
Created July 26, 2022 18:32
validate cell of array matrix
var csv = [
["id", "nome", "cidade_id"],
[23, "alex", "pereiro"],
[23, "alex", "pereiro"],
[23, "alex", 3],
]
const col= csv[0][2] // cidade_id
const cel = typeof csv[3][2]; // 3