Skip to content

Instantly share code, notes, and snippets.

View jgcmarins's full-sized avatar

João Marins jgcmarins

View GitHub Profile
@jgcmarins
jgcmarins / setup-env.ts
Created April 24, 2024 20:44
vitest config with setup and process.env mock
// https://github.com/vitest-dev/vitest/issues/1575#issuecomment-1439286286
export const setup = () => {
process.env.TZ = 'UTC';
process.env.NODE_ENV = 'test';
// add process.env mocks
};
@jgcmarins
jgcmarins / fix.md
Last active March 17, 2024 12:32
brew mongodb-community error

check mongod process

sudo lsof -iTCP -sTCP:LISTEN -n -P

kill the process

sudo kill <mongod_pid>
@jgcmarins
jgcmarins / serverless-api-gateway.yml
Created February 15, 2024 13:51
Multiple Lambdas with a single API Gateway
# serverless-api-gateway.yml
service: central-api-gateway
provider:
name: aws
runtime: nodejs14.x
stage: dev
region: sua-região
resources:
@jgcmarins
jgcmarins / index.js
Created January 10, 2024 22:51
Aleph Tech Interview Problem
/**
Given an integer array arr of distinct integers and an integer k.
A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], the larger integer wins and remains at position 0, and the smaller integer moves to the end of the array. The game ends when an integer wins k consecutive rounds.
Return the integer which will win the game.
It is guaranteed that there will be a winner of the game.
Example 1:
Input: arr = [2,1,3,5,4,6,7], k = 2
Output: 5
@jgcmarins
jgcmarins / xlsxToPdfChatGPT.js
Created November 8, 2023 19:15
Chat GPT code to generate pdf from xlsx
const fs = require('fs');
const { PDFDocument, rgb } = require('pdf-lib');
const ExcelJS = require('exceljs');
// Function to convert XLSX to PDF
async function convertXlsxToPdf(inputXlsxPath, outputPdfPath) {
// Create a new PDF document
const pdfDoc = await PDFDocument.create();
// Load the XLSX file
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(inputXlsxPath);
@jgcmarins
jgcmarins / decision-matrix.md
Created September 25, 2023 14:49
Looking for a new career opportunity? Use this table to create a ranking of all job offers

Table of concepts and definitions

Concept Definition
Autonomy How well will this company give me autonomy to do my job?
Freedom How much freedom will I have to balance work and personal life?
Responsibilities What level of responsibilities will I have, and how extensive will they be?
Culture How well does this company's culture align with my values, and how open is the company to allowing me to contribute to the culture I believe in?
Tech Stack How closely does the tech stack used by this company align with my preferences, and to what extent is the company willing to allow me to use the stack I prefer?
Personal Growth How big is the potential of this company to help me keep growing?
@jgcmarins
jgcmarins / index.js
Created August 18, 2023 13:09
New Encryption Key
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
@jgcmarins
jgcmarins / Dockerfile
Created August 10, 2022 17:39
Python Dockerfile with FatAPI
FROM python:3.10
WORKDIR /code
#COPY ./requirements.txt /code/requirements.txt
COPY ./ /code/
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
#COPY ./app /code/app
@jgcmarins
jgcmarins / MyPrivatePage.ts
Created July 11, 2022 22:37
Next.js SSR authentication and routing between public and private pages with getServerSideProps and cookies
import type { NextPage } from 'next';
import { getServerSidePropsPrivate } from '../../../middlewares/getServerSidePropsPrivate';
const MyPrivatePage: NextPage = ({ me }) => {
// use me data
/* code goes here */
};
export const getServerSideProps = getServerSidePropsPrivate;