Skip to content

Instantly share code, notes, and snippets.

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

Gabriel Marmitt gabrielmlinassi

🏠
Working from home
View GitHub Profile
@gabrielmlinassi
gabrielmlinassi / fp-composition-generics.ts
Created February 22, 2023 14:48
Example of Functional Programming composition funciton with TypeScript Generics
interface IMealCategory {
id: number
key: 'desert' | 'slow-cook' | 'breakfast' | 'protein'
}
const getMealCategoryBy = <T extends IMealCategory, K extends keyof IMealCategory>(mealCategories: T[], by: K) => {
return (value: T[K]) => {
return mealCategories.find((mealCategory) => {
return mealCategory[by] === value
})
@gabrielmlinassi
gabrielmlinassi / dialog.tsx
Created December 3, 2022 21:56
radixui dialog + specialized dialog
import * as DialogPrimitive from '@radix-ui/react-dialog'
import CloseIcon from 'components/icons/CloseIcon'
import React from 'react'
const classes = {
overlay: /* tw: */ `fixed inset-0 bg-black/30 rdx-state-open:animate-fade-in rdx-state-closed:animate-fade-out`,
content: /* tw: */ `fixed left-1/2 top-1/2 -translate-y-1/2 -translate-x-1/2 w-[calc(100%-40px)] h-[calc(100%-40px)] md:h-auto max-w-[900px] overflow-hidden rounded-md drop-shadow-card bg-white outline-none rdx-state-open:animate-fade-in rdx-state-closed:animate-fade-out`
}
type DialogProps = {
@gabrielmlinassi
gabrielmlinassi / ShopPageMainSection.tsx
Last active December 13, 2022 18:39
Example working with variant
import { EExperimentVersion } from '@/types'
import ProductCardA, { type IProductCardAProps } from './ProductCardA'
import ProductCardC, { type IProductCardCProps } from './ProductCardC'
type PropsVariantA = {
variant?: Extract<keyof typeof EExperimentVersion, 'a'>
} & IProductCardAProps
type PropsVariantC = {
import React, { ReactNode } from 'react'
type CardProps = {
children: React.ReactNode
}
const Slots = {
image: null,
title: null,
content: null,
import cn from 'classnames'
import useEmblaCarousel, { UseEmblaCarouselType } from 'embla-carousel-react'
import React, { useCallback, useContext, useEffect, useState } from 'react'
import { NextButton, PrevButton } from './CarouselButtons'
const Context = React.createContext<{
emblaRef: UseEmblaCarouselType[0]
thumbRef: UseEmblaCarouselType[0]
/**
* @deprecated Use the new {@see [Tooltip](../common/Tooltip/Tooltip.tsx)} component instead.
*/
@gabrielmlinassi
gabrielmlinassi / debugger-setup.txt
Created November 8, 2022 00:28
Setup VSCode Debbuger (Best Way)
# .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
@gabrielmlinassi
gabrielmlinassi / this-was-though.js
Last active October 14, 2022 17:01
Node with multiple Requests with `request` lib. With Promises.
const request = require("request");
const baseUrl = "https://jsonmock.hackerrank.com/api/football_matches";
async function myReq(url) {
return new Promise((resolve) => {
request.get(url.toString(), (err, response, body) => {
const data = JSON.parse(body);
resolve(data);
});
@gabrielmlinassi
gabrielmlinassi / test-swr-data-transformation.tsx
Last active October 16, 2022 13:29
Test SWR data transformations
import * as React from "react";
import useSWR, { SWRConfig } from "swr";
import { ErrorBoundary } from "react-error-boundary";
import axios from "axios";
// grab it with Swagger instead of manually write
interface PokemonDTO {
abilities: {}[];
base_experience: number;
forms: {}[];
@gabrielmlinassi
gabrielmlinassi / errorHandlingWithTS.ts
Last active October 13, 2022 13:11
Handle error with TypeScript
interface Pokemon {
id: number;
name: string;
height: number;
types: { id: number; name: string }[];
}
type GetPokemonSuccessResult = { isOk: true; data: Pokemon; error: null };
type GetPokemonErrorResult = { isOk: false; data: null; error: string };
type GetPokemonResult = GetPokemonSuccessResult | GetPokemonErrorResult;