Skip to content

Instantly share code, notes, and snippets.

View JPBM135's full-sized avatar
🎯
Focusing

João Pedro Borges Martins JPBM135

🎯
Focusing
View GitHub Profile
@JPBM135
JPBM135 / logger.ts
Created October 3, 2024 07:16
Useful Logger
import { inspect } from "node:util";
import kleur from "kleur";
kleur.enabled = true;
inspect.defaultOptions.depth = 10;
inspect.defaultOptions.maxArrayLength = 100;
interface ILoggerAdapter {
debug(prefix: string, message: string, ...args: any[]): void;
@JPBM135
JPBM135 / a_README.md
Last active September 26, 2024 08:23
Tools for mine server

My folder structure

Path Description
/home/minecraft_server/ The Minecraft server itself
/home/minecraft_server/run.sh The script to start the server
/home/minecraft_server/server.properties The server properties file
`/home/to
@JPBM135
JPBM135 / toggleScroll.ts
Created September 16, 2024 20:10
Block Scroll and Scrollbar
/*
37 - ArrowUp
38 - ArrowDown
39 - ArrowRight
40 - ArrowLeft
32 - Space
33 - PageUp
34 - PageDown
35 - End
36 - Home
@JPBM135
JPBM135 / formularizeInput.ts
Last active September 6, 2024 20:09
Obj to Form
import { FormGroup, FormArray, FormControl } from '@angular/forms';
import { InputMaybe } from '@generated/graphql';
type ExtractTypeFromInputMaybe<T> = NonNullable<T> extends InputMaybe<infer U> ? U : T;
type FormularizeRecord<T> =
ExtractTypeFromInputMaybe<T> extends Record<string, unknown>
? FormGroup<{ [K in keyof T]: FormularizeObject<NonNullable<T[K]>> }>
: never;
@JPBM135
JPBM135 / base.service.ts
Last active August 26, 2024 11:47
PrismaGenericbaseService.ts
import { IPaginatedType } from "@common/generics/paginated.type";
import { useConnection } from "@common/utils/connection";
import { paginated } from "@common/utils/paginated";
import { PrismaService } from "@infra/prisma/pprisma.service";
import { Prisma } from "@prisma/client";
import { Result } from "@prisma/client/runtime/library";
type PrismaModelsUnion = Prisma.TypeMap["meta"]["modelProps"];
// Get the model type from the prisma client based on the model name
@JPBM135
JPBM135 / Timestamp.ts
Created August 11, 2024 02:53
Timestamp class to help with time conversion
export class Timestamp {
public static SECOND_IN_MILLISECONDS = 1000;
public static MINUTE_IN_MILLISECONDS = 60 * Timestamp.SECOND_IN_MILLISECONDS;
public static HOUR_IN_MILLISECONDS = 60 * Timestamp.MINUTE_IN_MILLISECONDS;
public static DAY_IN_MILLISECONDS = 24 * Timestamp.HOUR_IN_MILLISECONDS;
private readonly _timestampMilliseconds: number;
private constructor(timestampMilliseconds: number) {
this._timestampMilliseconds = timestampMilliseconds;
@JPBM135
JPBM135 / create-keys.sh
Created July 31, 2024 09:05
Nginx config for server client and /api with cloudflare
cd ~
mkdir sslcertificates
openssl req -x509 -newkey rsa:4096 -keyout privatekey.pem -out certificate.pem -days 365 -nodes -subj '/CN=localhost'
@JPBM135
JPBM135 / hack.js
Created July 31, 2024 03:22
Hack import.meta.url with esbuild esm to cjs
const metaUrl = Reflect.has(globalThis, 'require') ? import.meta.url : pathToFileURL(__filename);
@JPBM135
JPBM135 / tranparency_report.md
Last active August 11, 2024 03:09
Transparency Report undocumented API
@JPBM135
JPBM135 / uploadFolderToApplicationEmojis.mjs
Last active September 20, 2024 11:50
Sync folder to discord application emojis
import { readdirSync, readFileSync, writeFileSync } from "fs";
import { setTimeout } from "timers/promises";
const APPLICATION_ID = "APPLICATION_ID";
const TOKEN =
"BOT_TOKEN";
const discordApiUrl = `https://discord.com/api/v10/applications/${APPLICATION_ID}/emojis`;
const headers = {