Skip to content

Instantly share code, notes, and snippets.

View Gerrit0's full-sized avatar

Gerrit Birkeland Gerrit0

View GitHub Profile
@Gerrit0
Gerrit0 / README.md
Last active March 16, 2020 01:59
Powershell Template Replacement

replace.ps1

This is a script to replace placeholders like {name} in a Word document with their values as defined in an Excel spreadsheet.

Usage

  1. Save replace.ps1 below somewhere on your machine.
  2. Create a Word document with your message, for example:

Hello {Name},

// ==UserScript==
// @name Block GIF avatars
// @namespace https://gerritbirkeland.com/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://discord.com/*
// @grant none
// ==/UserScript==
//@ts-check
'use strict';
const fs = require('fs');
const ts = require('typescript');
const path = require('path');
const Module = require('module');
// These are declared as globals
const SKIP_MODULES = new Set([
import { ok as assert } from 'assert'
import { readFile, writeFile } from 'fs/promises'
import { getHighlighter, getTheme } from 'shiki'
// This is bad... but Shiki doesn't export it from the root.
import { Highlighter } from 'shiki/dist/highlighter'
import { TLang } from 'shiki-languages'
import { TTheme } from 'shiki-themes'
import { createElement, JSX } from 'preact'
@Gerrit0
Gerrit0 / different-subtype.md
Last active July 31, 2021 13:33
Different subtype error explanation

The different subtype error is usually caused by two mistakes:

  1. Providing a default value which might not be specific enough.
function broke<T extends string>(x: T = "error"): T { return x }
//                               ^^^^^^^^^^^^^^
// Type 'string' is not assignable to type 'T'.
//  'string' is assignable to the constraint of type 'T', but
//  'T' could be instantiated with a different subtype of
//  constraint 'string'.
@Gerrit0
Gerrit0 / build.js
Last active May 6, 2023 23:23
A esbuild setup with optional watching + server with live reload
// @ts-check
const fs = require("fs");
const http = require("http");
const esbuild = require("esbuild");
const { join } = require("path");
// ===== Configuration =====
const port = parseInt(process.argv[process.argv.indexOf("--port") + 1]) || 8080;
// @ts-check
/**
* typedoc-plugin-not-exported
* TypeDoc plugin that forces inclusion of non-exported symbols (variables)
* Originally from https://github.com/TypeStrong/typedoc/issues/1474#issuecomment-766178261
* https://github.com/tomchen/typedoc-plugin-not-exported
* CC0
*/
const {
@Gerrit0
Gerrit0 / type.tsx
Created June 9, 2024 16:24
TypeDoc type print width estimation
function aggregate<T>(arr: T[], fn: (item: T) => number) {
return arr.reduce((sum, it) => sum + fn(it), 0);
}
function aggregateWithJoiner<T>(arr: T[], fn: (item: T) => number, joiner: string) {
return arr.reduce((sum, it) => sum + fn(it), 0) + (arr.length - 1) * joiner.length;
}
// Used to check if we should split a union into multiple lines.
export function estimatePrintWidth(type: Type): number {
return type.visit({
@Gerrit0
Gerrit0 / post.md
Created November 15, 2024 19:50
TypeScript - Type Safe Plugin System

+++ title = "TypeScript - Type Safe Plugins" date = 2024-10-14 +++

A recent question in the TypeScript Discord needs more space than is available there. It happens to be a pretty good question for providing a walkthrough for how I create complex systems, so I am roughly reproducing it here to be able to reference it in the future.