Skip to content

Instantly share code, notes, and snippets.

View joaobispo2077's full-sized avatar
💭
Solving problems

João Bispo joaobispo2077

💭
Solving problems
View GitHub Profile
@joaobispo2077
joaobispo2077 / prisma.mock.ts
Created July 3, 2023 12:36
Sequelize and Prisma Mock Factory for Nest.js
import { PrismaClient } from '@prisma/client';
import { mockDeep, DeepMockProxy } from 'jest-mock-extended';
import { PrismaService } from 'src/shared/services/prisma.service';
type CreatePrismaProviderMockResponse = {
provide: typeof PrismaService;
useValue: DeepMockProxy<PrismaClient>;
};
@joaobispo2077
joaobispo2077 / MakePartial.ts
Created July 9, 2022 17:46
MakePartial Generic - Transform some keys from a Type into Optional Keys because built-in "Partial" Generic apply optional into all keys, but this only into few keys.
export type MakePartial<
OriginalType,
KeyFromOriginalType extends keyof OriginalType,
> = Omit<OriginalType, KeyFromOriginalType> &
Partial<Pick<OriginalType, KeyFromOriginalType>>;
/* Here is how to use: */
// type User = {
// name: string;
// age: number;
@joaobispo2077
joaobispo2077 / queryGSI.js
Created May 21, 2022 15:37
Dynamo DB, Query Global Secondary Index (GSI) with DynamoDB Toolbox and with AWS SDK in Node.js
"use strict";
require("dotenv/config"); // Load environment variables from .env file
// 1. Table definition
const DynamoDB = require('aws-sdk/clients/dynamodb');
const { Table } = require('dynamodb-toolbox');
const DocumentClient = new DynamoDB.DocumentClient();
const GLOBAL_SECONDARY_INDEX_NAME = '_et-pk-index';
@joaobispo2077
joaobispo2077 / docker-compose.yml
Created May 2, 2022 14:50
Dockerfile with build proxy and set proxy into container of an api.
version: '3'
services:
api:
build:
context: .
dockerfile: Dockerfile
args:
http_proxy: "http://xxx.xx.xx.xxx:3128"
https_proxy: "http://xxx.xx.xx.xxx:3128"
@joaobispo2077
joaobispo2077 / jetbrains-mono.css
Created February 28, 2022 21:10
CSS for using JetBrains Mono on my site
@font-face {
font-family: "JetBrains Mono Regular";
src: url("https://raw.githubusercontent.com/JetBrains/JetBrainsMono/master/web/eot/JetBrainsMono-Regular.eot")
format("embedded-opentype"),
url("https://raw.githubusercontent.com/JetBrains/JetBrainsMono/master/web/woff2/JetBrainsMono-Regular.woff2")
format("woff2"),
url("https://raw.githubusercontent.com/JetBrains/JetBrainsMono/master/web/woff/JetBrainsMono-Regular.woff")
format("woff"),
url("https://raw.githubusercontent.com/JetBrains/JetBrainsMono/master/ttf/JetBrainsMono-Regular.ttf")
format("truetype");
@joaobispo2077
joaobispo2077 / Dockerfile
Created February 27, 2022 18:54
Simple Docker file for Python
FROM python:3.9-alpine
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY src src
@joaobispo2077
joaobispo2077 / Dockerfile
Last active February 27, 2022 15:15
Node.js Javascript Simple Dockerfile Example
FROM node:16-alpine
WORKDIR /app
COPY package*.json .
RUN npm install
COPY src src
@joaobispo2077
joaobispo2077 / request.js
Created February 18, 2022 19:50
request with curl and fetch api
// curl -d '' -H "Content-Type: application/json" -X POST url
(async () => {
try {
const rawResponse = await fetch('url, {
method: 'POST',
headers: {
'Accept': 'application/json',
@joaobispo2077
joaobispo2077 / setupJsonServer.js
Created November 6, 2021 14:58
Setup json server with dynamic actual machine ip address from node js cli using native packages
/* eslint-disable import-helpers/order-imports */
/* eslint-disable @typescript-eslint/no-var-requires */
/* prerequisites:
- in the root of the project create the file in ./scripts/setupJsonServer.js
- json-server installed in the project or globally.
*/
// to excute run "node .setupJsonServer.js"
// in package.json add following key value script: "dev:server": "node ./scripts/setupJsonServer.js"
@joaobispo2077
joaobispo2077 / randomBeautyPallet.ts
Created August 30, 2021 14:51
Beauty pallet to use when is without any pallet
export default {
colors: {
primary: '#00bcd4',
secondary: '#ff9800',
tertiary: '#ff5722',
quaternary: '#9c27b0',
quinary: '#2196f3',
senary: '#009688',
white: '#ffffff',
black: '#000000',