Skip to content

Instantly share code, notes, and snippets.

View g4rcez's full-sized avatar
🇧🇷
🎧

Allan Garcez g4rcez

🇧🇷
🎧
View GitHub Profile
import { formToJson } from "brouther";
import React, { useCallback, useEffect, useRef, useState } from "react";
import { AllPaths, Is, setPath } from "sidekicker";
import { z, ZodArray, ZodNumber } from "zod";
import { formReset, InputProps } from "~/components";
export const convertPath = (path: string) => path.replace("[", ".").replace("]", "").split(".");
export const getSchemaShape = <T extends z.ZodObject<any>>(name: string, schema: T) =>
convertPath(name).reduce((acc, el) => {
import axios from "axios";
export type Country = {
name: Name;
tld?: string[];
cca2: string;
ccn3?: string;
cca3: string;
cioc?: string;
independent?: boolean;
export const initObserver = (root: HTMLElement) => {
const dataset = {
ga: "data-ga",
inspect: "data-inspect",
};
const observer = new MutationObserver((params) => {
params.forEach((node) => {
if (!(node.target as any).querySelectorAll) return [];
const htmlElement: HTMLElement = node.target as any;
import fs from "fs";
import ts from "typescript";
const isType = (node: ts.Node) =>
ts.isTypeAliasDeclaration(node) ||
(ts.isInterfaceDeclaration(node) && node.name && node.name);
type DocEntry = {
name?: string;
fileName?: string;
import { formatISO,parse } from "date-fns";
const getUtcDate = (date: Date) => {
const r = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{3})/;
const [, ...s] = r.exec(date.toISOString())!;
return (Date.UTC as any)(...s);
};
const parseFromFormat = (strDate: string, format: string) => {
const p = parse("2020.10.06 09:24:06", "yyyy.MM.dd HH:mm:ss", new Date());
const utc = getUtcDate(p);
import { assocPath } from "ramda";
import { useClassNames } from "hulks";
import React, {
Fragment,
useCallback,
useEffect,
useMemo,
useState,
} from "react";
import { Arrow } from "./arrow";
import axios, { AxiosInstance, AxiosRequestConfig, AxiosStatic, CancelTokenSource } from "axios";
import { useCallback, useEffect, useMemo, useRef } from "react";
type Tokens = { [k: string]: CancelTokenSource | undefined };
const createUid = () => Math.random().toString(36).substring(16);
type Http = "get" | "head" | "options" | "delete";
type HttpBody = "post" | "put" | "patch";
@g4rcez
g4rcez / use-axios.ts
Last active November 30, 2020 05:16
use-axios hook to avoid memory leak on unmout react components
import axios, { AxiosInstance, AxiosRequestConfig, AxiosStatic, CancelTokenSource } from "axios";
import { useCallback, useEffect, useMemo, useRef } from "react";
type Tokens = { [k: string]: CancelTokenSource | undefined };
const createUid = () =>
Math.random()
.toString(36)
.substring(16);
@g4rcez
g4rcez / joked-components.tsx
Created October 28, 2020 03:22
A complete example for how to create your styled-components
import classNamesDedupe from "classnames/dedupe";
import React, { useState, DependencyList, useMemo } from "react";
type ClassArray = ClassValue[];
type ClassDictionary = { [id: string]: any };
export type ClassValue = string | number | ClassDictionary | ClassArray | undefined | null | boolean;
export const useClassNames = (dependency: DependencyList, ...classes: ClassValue[]) =>
import React, { useLayoutEffect, useMemo, useState } from "react";
import { useClassNames } from "styleguide";
type Html = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
type StyledArgs<E, T> = ((args: E & T) => string | number) | string | number;
function Styled<ExtraProps = unknown, Element = Html>(tag: string) {
return ([first, ...placeholders]: TemplateStringsArray, ...a: StyledArgs<Element, ExtraProps>[]) => {
return ({ children, ...props }: Html & ExtraProps) => {