Skip to content

Instantly share code, notes, and snippets.

View joeyjiron06's full-sized avatar

Joey Jiron joeyjiron06

View GitHub Profile
@joeyjiron06
joeyjiron06 / Vitest + Jsdom + React Testing Library.md
Created June 19, 2024 17:41
Vitest + Jsdom + React Testing Library

Vitest + Jsdom + React Testing Library

TLDR; very quick setup to add vitest, jsdom and react testing library

install dependencies

pnpm i --save-dev vitest jsdom @testing-library/react @testing-library/jest-dom
@joeyjiron06
joeyjiron06 / Vite + Typescript import aliases.md
Last active June 13, 2024 21:22
Setup ViteJS and Typescript to use import alias

Vite + Typescript import aliases

This is how you add import aliases in a vite project that uses Vite.

It requires you to update both your tsconfig file as well as your vite config so that vite knows how to import the aliases.

tsconfig.jcon

{

React Context + Reducer + Typescript

I followed the recommendation provided by the react docs that suggest how to use a reducer in conjuction with context.

There is a lot of boiler plate just to add 1 action and a reducer that handles the action.

Before

This is what it looks like before my simplified API, which at first glance doesn't look bad for small demo apps, but quickly adds up over time.

@joeyjiron06
joeyjiron06 / VITE + ESLINT.md
Last active June 27, 2024 20:24
VITE + ESLINT

Adding ESLint to Vite

Adds typescript support for ESLint, prettier integration for better code formatting and eslint-plugin-jsx-a11y for accesibility errors.

pnpm i --save-dev eslint @typescript-eslint/parser eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-config-prettier

ESLint config

@joeyjiron06
joeyjiron06 / Astro + Static HTML Setup.md
Last active June 17, 2024 17:44
Static HtML website with Astro setup

Astro + Static HTML Setup

These are the commands i use to setup and Astro static html website with all the tools i like using pnpm

create new astro project

pnpm create astro@latest

install eslint and plugins

@joeyjiron06
joeyjiron06 / .eslintrc
Last active December 9, 2022 15:51
Generate a new vite react project with all depencies needed for local dev
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"airbnb",
"airbnb/hooks"
],
"rules": {
@joeyjiron06
joeyjiron06 / README.md
Created December 22, 2021 18:58
Ping an address and get a promise result back

Ping (Node JS)

Ping a simple tcp socket and return a promise that let's you konw if the address is a alive or not.

const readline = require("readline");
/**
* Writes a certain percentage number to the node js console
*/
const writePercentate = percentage => {
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0);
process.stdout.write(`loading... ${percentage}%`);
const Couchbase = require('couchbase');
const Promise = require('bluebird');
class Bucket {
constructor(options) {
this.options = options;
}
async connect() {
const {

KafkaDocker

A simple nodejs wrapper around starting and stopping kafka locally. Can be used for test suites or just running against your service locally.

Example Usage

const KafkaDocker = require('./kafkaDocker');

const KAFKA_TOPIC = 'test';