Skip to content

Instantly share code, notes, and snippets.

View Alexisvt's full-sized avatar
🎯
Focusing

Alexis Villegas Torres Alexisvt

🎯
Focusing
  • San Jose, Costa Rica
View GitHub Profile
@Alexisvt
Alexisvt / event-loop.md
Last active August 10, 2023 15:38
What is the Event loop in JavaScript - study notes

What is the Event loop in Javascript

JavaScript code runs single threaded. There is just one thing happening at a time.

This is good because devs dont need to worry about concurrency issues, the only caveat is to know how not to block that single thread like synchronous network calls or infinite loops.

In most browser there is an event loop for every browser tab, in other words, the environment manages multiple concurrent event loops, to handle API calls for example, Web Workers run in their own event loop as well.

You mainly need to be concerned that your code will run on a single event loop, and write code with this thing in mind to avoid blocking it.

@Alexisvt
Alexisvt / DataAttributes.ts
Created February 10, 2023 23:10
Interface to support data-* attributes in props due to a design decision in TypeScript.
export interface DataAttributes {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[n: `data-${string}`]: any
}
// more info about it:
// https://github.com/microsoft/TypeScript/issues/47211
// https://github.com/microsoft/TypeScript/issues/28960
@Alexisvt
Alexisvt / test-utils.tsx
Created February 10, 2023 02:21
Test utility for customize testing-library with react-query
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render as rtlRender } from '@testing-library/react'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function render(ui: React.ReactElement, { ...renderOptions } = {} as any) {
const queryClient = new QueryClient()
const Wrapper = ({ children }: { children: React.ReactNode }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
)
@Alexisvt
Alexisvt / jest-recipes.md
Last active September 1, 2022 10:30
Jest and testing-library recipes

Jest Recipes

How to mock some windows functions

In this example, Im mocking the open function of the window object, then in the actual test block, Im returning an object with a focus property that also Im mocking.

Describe('some test', () => {

  let spyWindowOpen;
@Alexisvt
Alexisvt / README.md
Last active January 5, 2022 23:45
Just a random set of commands for Docker and Kubernetes

Docker and Kubernetes commands

Docker commands

This build an image base on a Dockerfile and assign a tag to it and a version number

docker build -t custom/tag:0.0.1 .

Create and start a container based on the provided image id or tag

@Alexisvt
Alexisvt / README.md
Last active September 10, 2021 00:24
Little guide about how to setup a Vite VueJS project with TypeScript, TailwindCSS, ESLint and Prettier support.

Little guide about how to setup a Vite VueJS project with TypeScript, TailwindCSS, ESLint and Prettier support.

Initialize the project

Run this command

yarn create vite <my-awesome-project> --template vue-ts

This will create a VueJS project with TypeScript support, but it doesn't add the configuration for Prettier or Eslint, let's add that.

@Alexisvt
Alexisvt / npm-commands.md
Last active February 24, 2022 23:52
Common npm commands

Notes about npm and Yarn v1

How to install packages globally

For yarn use this command

yarn global add <package_name>

For npm use this instead

@Alexisvt
Alexisvt / mpv.conf
Last active January 2, 2021 17:45
My mpv.conf file settings
keep-open=yes
reset-on-next-file=pause
geometry=50%x50%
pause
@Alexisvt
Alexisvt / proto3.md
Created September 4, 2020 17:47 — forked from figassis/proto3.md
Protocol Buffer CheatSheet

Proto3 Cheat Sheet

Information From: https://developers.google.com/protocol-buffers/docs/proto3

A few rules

  • Declaring Message In Protocol Buffer:

  • As you can see, each field in the message definition has a unique number.

  • Field numbers identify fields in message binary format. Should not be changed once message is in use

@Alexisvt
Alexisvt / go-commands.md
Last active August 17, 2020 01:29
Some useful go commands

List of useful go commands

go help

Display useful information about the different commands available. If we need more information about an specific command, type:

# Where [command] can be any of the available commands
go help [command]