Skip to content

Instantly share code, notes, and snippets.

@TimKochDev
TimKochDev / register-fonts.ts
Last active May 9, 2024 19:35
PDF visual regression testing using Playwright (e.g. react-pdf)
// Just to show what I had to deal with. Do NOT copy. React-pdf encourages you to import font from CDN directly.
import LatoBold from "../../../assets/fonts/Lato-Bold.ttf";
import LatoLight from "../../../assets/fonts/Lato-Light.ttf";
import Lato from "../../../assets/fonts/Lato-Regular.ttf";
import openSansFont from "../../../assets/fonts/OpenSans-Light.ttf";
export const PDF_BOLD_FONT_NAME = "Lato Bold";
export const PDF_LIGHT_FONT_NAME = "Lato Light";
@TimKochDev
TimKochDev / migrate-users-with-password-hashes-to-keycloak.js
Created October 4, 2024 16:49
Import users with password hashes to Keycloak. Watch your encodings.
// Before moving to Keycloak, I used the following code to generate user credentials
const crypto = require("crypto");
const salt = crypto.randomBytes(16).toString("hex");
const hash = crypto
.pbkdf2Sync(password, this.salt, 10000, 64, "sha512")
.toString("hex");
// HEADS UP: Even though the salt was created as random bytes and then converted to its hex representation,
// the hashing function interpreted it as UTF-8. So this yields the same hash as the following:
const sameHash = crypto