Skip to content

Instantly share code, notes, and snippets.

View BrunoQuaresma's full-sized avatar

Bruno Quaresma BrunoQuaresma

View GitHub Profile
@BrunoQuaresma
BrunoQuaresma / withWebSocket.tsx
Created February 23, 2024 14:32
Storybook decorator that supports WebSocket messages
export const withWebSocket = (Story: FC, { parameters }: StoryContext) => {
if (!parameters.webSocket) {
console.warn(
"Looks like you forgot to add websocket messages to the story",
);
}
// @ts-expect-error -- TS doesn't know about the global WebSocket
window.WebSocket = function () {
return {
@BrunoQuaresma
BrunoQuaresma / tailwind-colors.js
Last active May 15, 2023 17:31
TailwindCSS colors object to be used outside of Tailwind projects like MUI
// Generated from https://tailwindcss.com/docs/customizing-colors
export default {
slate: {
50: "#f8fafc",
100: "#f1f5f9",
200: "#e2e8f0",
300: "#cbd5e1",
400: "#94a3b8",
500: "#64748b",
600: "#475569",
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@BrunoQuaresma
BrunoQuaresma / blog.tsx
Created May 29, 2021 16:39
Next/mdx blog index page
export async function getStaticProps() {
const postDirectory = path.join(process.cwd(), "src/pages/blog");
const postFilenames = fs
.readdirSync(postDirectory)
.filter((file) => path.extname(file).toLowerCase() === ".mdx");
const postModules = await Promise.all(
postFilenames.map(async (p) => require(`./${p}`))
);
return {
@BrunoQuaresma
BrunoQuaresma / initializeForm.js
Created August 25, 2020 14:48
Form Initialize for React
function initializeForm(form) {
return Object.keys(form).reduce((newForm, key) => {
let value
if(form[key] === null || form[key] === undefined) {
value = ''
} else if(typeof form[key] === 'string') {
value = form[key]
} else if(typeof form[key] === 'object') {
value = initializeForm(form[key])
@BrunoQuaresma
BrunoQuaresma / nextapimock.ts
Last active July 18, 2023 17:12
NextApiResponse and NextApiRequest mocks
import { IncomingMessage } from 'http'
import {
NextApiRequestCookies,
NextApiRequestQuery,
} from 'next/dist/next-server/server/api-utils'
import { Socket } from 'net'
import { ServerResponse } from 'http'
import { NextApiRequest, NextApiResponse } from 'next'
import { Env } from 'next/dist/lib/load-env-config'
@BrunoQuaresma
BrunoQuaresma / zeit-now-test-utils.ts
Created April 19, 2020 05:48
Zeit Now Test Utils for Cloud Functions/Lambda
import logsFunction from '../logs';
import { IncomingMessage, ServerResponse } from 'http';
import { Socket } from 'net';
import { NowRequestQuery, NowRequestCookies, NowRequestBody } from '@now/node';
class NowRequestMock extends IncomingMessage {
public query: NowRequestQuery = {};
public cookies: NowRequestCookies = {};
public body: NowRequestBody;

Keybase proof

I hereby claim:

  • I am brunoquaresma on github.
  • I am faunadb (https://keybase.io/faunadb) on keybase.
  • I have a public key ASDHoShbI8liosOWuuCGFWQ8_f4dfamUjTQt-aL5YZ8sMwo

To claim this, I am signing this object:

@BrunoQuaresma
BrunoQuaresma / types_spec.mkd
Last active July 24, 2019 16:11
Faunadb-JS types spec

Type improvements for FaunaDB JS driver

This is a draft where we can think of how to improve the FaunaDB JS driver type system, so if you have any suggestions on how we can improve this, feel free to comment and submit your changes.

1. Acessible values in the root path

Current

import faunadb from "faunadb";

type Note = {
@BrunoQuaresma
BrunoQuaresma / brazil_cities.json
Created December 21, 2017 23:57
Todas as cidades brasileiras
["Acrelândia - AC","Assis Brasil - AC","Brasiléia - AC","Bujari - AC","Capixaba - AC","Cruzeiro do Sul - AC","Epitaciolândia - AC","Feijó - AC","Jordão - AC","Mâncio Lima - AC","Manoel Urbano - AC","Marechal Thaumaturgo - AC","Plácido de Castro - AC","Porto Acre - AC","Porto Walter - AC","Rio Branco - AC","Rodrigues Alves - AC","Santa Rosa do Purus - AC","Sena Madureira - AC","Senador Guiomard - AC","Tarauacá - AC","Xapuri - AC","Água Branca - AL","Anadia - AL","Arapiraca - AL","Atalaia - AL","Barra de Santo Antônio - AL","Barra de São Miguel - AL","Batalha - AL","Belém - AL","Belo Monte - AL","Boca da Mata - AL","Branquinha - AL","Cacimbinhas - AL","Cajueiro - AL","Campestre - AL","Campo Alegre - AL","Campo Grande - AL","Canapi - AL","Capela - AL","Carneiros - AL","Chã Preta - AL","Coité do Nóia - AL","Colônia Leopoldina - AL","Coqueiro Seco - AL","Coruripe - AL","Craíbas - AL","Delmiro Gouveia - AL","Dois Riachos - AL","Estrela de Alagoas - AL","Feira Grande - AL","Feliz Deserto - AL","Flexeiras - AL","Gir