Skip to content

Instantly share code, notes, and snippets.

View KoenBrouwer's full-sized avatar

Koen Brouwer KoenBrouwer

View GitHub Profile
@KoenBrouwer
KoenBrouwer / SessionStuff.tsx
Created November 14, 2024 14:20
React client component with navigator.credentials
"use client";
import { useState } from "react";
const challenge = new Uint8Array([1, 2, 3, 4, 5]);
const SessionStuff = () => {
const [user, setUser] = useState<Credential | undefined>(undefined);
if (!user) {
@KoenBrouwer
KoenBrouwer / command.txt
Created June 15, 2024 21:55
How to remove password protection when macOS Preview saves PDF with password
# Source: https://apple.stackexchange.com/questions/436596/preview-automatically-password-protects-pdf-when-saving
LC_ALL=C \
sed \
-i '' \
-e 's/\/EncryptMetadata false/\/EncryptMetadata true/g' \
./my-password-protected.pdf
@KoenBrouwer
KoenBrouwer / ensure-linear-history.ts
Created April 19, 2024 12:46
Script that can be used in a pipeline to ensure that it's been rebased onto master before merging.
import { execSync } from "child_process";
import gitlog from "gitlog";
const main = () => {
const getBase = () => execSync("git merge-base origin/master HEAD").toString().trim();
const getDesiredBase = () => execSync("git ls-remote origin master").toString().trim().split("\t")[0];
const shouldRebase = (): boolean => {
try {
const base = getBase();
@KoenBrouwer
KoenBrouwer / gist:4b71adc8bb68a853ed835a65459db58a
Created April 10, 2024 06:57
A script that i18n-ifies a word.
const word = process.argv[2];
// Shorten (s5n) the word like internationalization becomes i18n
const s5n = (word) =>
word.length <= 2 ? word : [
word.at(0),
word.length - 2,
word.at(-1),
].join("");
@KoenBrouwer
KoenBrouwer / gist:3f81826ff0d03d07bb00e9dbabd752eb
Created April 10, 2024 06:56
A script that caps a string to a maximum length and to make it unique adds a piece of a hash of itself to the end.
const crypto = require("crypto");
const words = process.argv.slice(2);
const maxWordLength = 20;
// Cap the name at 25 characters and replace the last 5 characters with the last 5 characters of the md5 hash of the word
const shortName = (word) => {
if (word.length <= maxWordLength) {
return word;
}
@KoenBrouwer
KoenBrouwer / calculate-permutations.js
Last active October 21, 2023 14:37
Simple NodeJS script that I used to create a list of all possible permutations of call chains for Vitest.
// This script creates a list of all possible permutations of call chains based on the Vitest Test API Reference (https://vitest.dev/api/).
// I used this to improve a package called veritem/eslint-plugin-vitest.
// For further context see: https://github.com/veritem/eslint-plugin-vitest/issues/275.
const fs = require("fs");
const percom = require("percom");
const data = [
{
names: ["beforeEach", "beforeAll", "afterEach", "afterAll"],
@KoenBrouwer
KoenBrouwer / git-author.sh
Last active April 23, 2023 19:31
When I forget to update my email
#!/bin/sh
# Use this to change your name and email in your Git history
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
@KoenBrouwer
KoenBrouwer / English.md
Created February 3, 2022 22:50
Recruiter Autoresponse Letter

Hi there,

Thank you for reaching out. I'm always interested in exploring new and exciting opportunities out there. As a software engineer I'm sure you can imagine that I get a very high volume of recruiters reaching out to me. It's a wonderful position of privilege to be in and I'm very thankful for it.

However, this means that I have absolutely no time to personally respond to every single one. Unfortunately most incoming messages do not match my ambitions and level of knowledge anyway. While I very much appreciate the fact that exceptionally talented and engaged recruiters reach out consistently, sorting serious and high quality opportunities from spam would be an actual full time job for me.

I would love to continue the conversation, but before I do, I'd like to level set around the level of seniority that you're looking for. Can you send along the company name, a job description and, total compensation details for the role you're reaching out in reference to? In the absence of detailed information rega

@KoenBrouwer
KoenBrouwer / ConditionalWrap.tsx
Last active December 28, 2020 00:19
Simple React component to condionally wrap something in JSX.
import React from "react";
interface ConditionalWrapProps {
condition: boolean;
wrap: (children: JSX.Element) => JSX.Element;
children: JSX.Element;
}
const ConditionalWrap: React.FC<ConditionalWrapProps> = ({condition, children, wrap}): JSX.Element =>
condition ? React.cloneElement(wrap(children)) : children;
@KoenBrouwer
KoenBrouwer / Example.tsx
Last active February 28, 2020 09:27
A React hook that checks if the browser is prefering darkMode, and using the useState hook to update accordingly.
import React, {useState, useEffect} from 'react';
import useDarkMode from "./useDarkMode";
const Example = () => {
const darkModePreference = useDarkMode();
const [theme, setTheme] = useState<string>(darkModePreference ? "dark" : "light");
useEffect(() => {
setTheme(darkModePreference ? "dark" : "light");
}, [darkModePreference]);