Skip to content

Instantly share code, notes, and snippets.

View kevinvdburgt's full-sized avatar
😸

Kevin van der Burgt kevinvdburgt

😸
View GitHub Profile
@kevinvdburgt
kevinvdburgt / jwt.ts
Created December 27, 2024 08:58
Simple jsonwebtoken wrapper with zod validation.
import { type SignOptions, type VerifyOptions, sign, verify } from 'jsonwebtoken';
import { z } from 'zod';
import { config } from '#infrastructure/config/config.js';
export const jwt = {
sign: <T extends object>(payload: T, options?: SignOptions) =>
sign(payload, config.jwt.privateKey, {
algorithm: 'RS512',
...options,
@kevinvdburgt
kevinvdburgt / encryption.ts
Created December 27, 2024 08:44
NodeJS asymmetric encryption
import { createCipheriv, createDecipheriv, privateDecrypt, publicEncrypt, randomBytes } from 'node:crypto';
import { config } from '#infrastructure/config/config.js';
export const encryption = {
encrypt: (buffer: Buffer) => {
const key = randomBytes(32);
const iv = randomBytes(16);
const cipher = createCipheriv('aes-256-cbc', key, iv);
const encryptedKey = publicEncrypt(config.encryption.publicKey, key);
export const AuthProvider: FunctionComponent<AuthProviderProps> = (props) => {
const { children } = props;
const [token, setToken] = useLocalStorage<string | null>({
key: 'auth.token',
defaultValue: null,
getInitialValueInEffect: true,
});
const [user, setUser] = useLocalStorage<UsersMeResponse | null>({
const simulateSlowHttpRequest = async (dummyData: string): Promise<string> =>
new Promise<string>((resolve) => setTimeout(() => resolve(dummyData), 2000));
const bootstrap = async (): Promise<void> => {
/**
* Test A
*/
const startA = Date.now();
const aA = await simulateSlowHttpRequest('a');
// modules/example/interfaces/listing.interface.ts
export interface ListingInterface {
names: string[];
}
// modules/example/dtos/listing.dto.ts
export class ListingPayloadDto implements ListingInterface {
// class-validator validations
// @nestjs/swagger decorators
readonly names!: string[];
{
"products": [
{
"uuid": "bd24626d-a078-403d-ae5e-6df5d9690908",
"name": "Minecraft Server (Modded)"
},
{
"uuid": "d8721919-a652-462b-95ac-b276db1412fb",
"name": "WordPress"
},
@kevinvdburgt
kevinvdburgt / prisma.service.ts
Created January 15, 2021 10:33
Prisma service using knex migrations.
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import knex from 'knex';
import knexfile from './knexfile';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
/**
* Waits for the database to be available.
*/
const bootstrap = async (): Promise<void> => {
// Do stuff
});
bootstrap().catch((error: Error) => {
// Send error to sentry or Slack
console.error(error);
});
@kevinvdburgt
kevinvdburgt / keybinds.md
Last active February 21, 2019 20:42
Play Rust - Keybinds

Keybinds for the game Rust

Press Q to auto-run, press Shift and W to cancel.

bind q forward;sprint

Press Z to permanently crouch and auto-attack, press Left Click and Control to cancel.

bind z attack;duck

Hold Z to crouch and auto-attack (only while pressed.)

bind z +attack;+duck

#!/bin/bash
WORKSPACE=$1
log() {
echo "[$(date +"%D %T")] $1" >> "$WORKSPACE/deployment.log"
echo $1
}
# Check if the workspace directory exists