Skip to content

Instantly share code, notes, and snippets.

View VitorLuizC's full-sized avatar

Vitor L Cavalcanti VitorLuizC

View GitHub Profile
@VitorLuizC
VitorLuizC / README.md
Last active June 17, 2021 17:30
Exemplo correto e incorreto para guias de padrões e boas práticas escritas em Markdown.

Exemplo de correto e incorreto na horizontal

✅ Correto ❌ Incorreto
import { useCallback, useEffect, useRef } from 'react';
/**
* Hook that provides start and stop functions to handle AnimationFrame API.
*/
const useAnimationFrame = () => {
const handleRef = useRef<null | number>(null);
const stop = useCallback(() => {
if (!handleRef.current) return;
@VitorLuizC
VitorLuizC / index.js
Created August 6, 2020 04:24
A way to execute unsafe code on Node.js.
'use strict';
const vm = require('vm');
const createContext = () => {
const context = Object.create(null);
return vm.createContext(context);
};
const execute = (code) => {
@VitorLuizC
VitorLuizC / README.md
Last active February 11, 2022 04:09
Artigos, projetos e outros links onde posso aprender TypeScript

Artigos, projetos e outros links onde posso aprender TypeScript

  • Advanced TypeScript - Stefan Baumgartner

    https://fettblog.eu/advanced-typescript-guide/

    No blog do Stefan, o fettblog, existe o guia de typescript avançado. Esse guia é um artigo que exibe outros artigos do blog numa lista, por ordem de complexidade e agrupados por tema. Os artigos explicam tópicos super úteis em TypeScript com bons exemplos e uma didática fantástica.

    O conteúdo está em inglês.

import { useCallback, useMemo, useState } from 'react';
type ValueOrPromiseValue<Value> = Value extends Promise<infer PromiseValue>
? PromiseValue
: Value;
const useLoading = () => {
const [ticks, setTicks] = useState(0);
const withLoading = useCallback(
@VitorLuizC
VitorLuizC / README.md
Last active July 17, 2020 00:16
Slides, links e outras informações sobre minha talk "Teoria das categorias aplicada com as mônadas Either e Maybe/Option".
@VitorLuizC
VitorLuizC / getLanguage.ts
Last active July 16, 2020 14:32
Caso de uso do Maybe/Option para resolver o idioma do usuário.
import * as Maybe from './main';
// ..:: Contexto ::..
enum LanguageEnum {
PORTUGUESE = 'pt-BR',
ENGLISH = 'en-US',
}
type User = {
/**
* Transforms blob to base64 using FileReader API.
* @param blob - A blob instance.
*/
const fromBlobToBase64 = (blob: Blob): Promise<string> => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onerror = (): void => {
reject(reader.error ?? new Error('Unknown error on FileReader.'));
type JsonObject = { [property: string]: Json };
type JsonArray = Json[];
type Json = null | boolean | number | string | JsonObject | JsonArray;
type NodeOf<T extends Json> = T extends JsonObject
? T
: T extends JsonArray
? T[number]