Skip to content

Instantly share code, notes, and snippets.

@karlrwjohnson
karlrwjohnson / README.md
Created June 8, 2024 19:38
Typescript types for Loki configuration file

This script generates a Typescript typedef file for Loki's configuration file.

I've also included the output of the script at time of writing. If major changes are made to Loki, the typedefs will fall out of date.

If you use Typescript to generate the Loki configuration (notably, all JSON is also YAML, so you can JSON.stringify a Typescript object), this file would be useful.

I haven't bothered putting this in a repo because I'd also feel the need to generate a pipeline to regenerate the file to keep it up to date, and re-publish it as an NPM package.

@karlrwjohnson
karlrwjohnson / split-graphql-files.mjs
Created July 24, 2023 17:38
Split GraphQL Schema files
/*
GraphQL schema file splitter
Not guaranteed to work 100% of the time -- I just needed it to work once, for me, in my project
But I'm saving it in case I need it again
Basic idea is that I started a project with a rather loose policy toward file organization.
Every file had multiple "things" in it.
But I wanted to split it up along the lines of "one file per thing".
@karlrwjohnson
karlrwjohnson / installing-postgres-ubuntu.md
Last active March 8, 2023 14:16
Installing latest Postgres on Ubuntu
@karlrwjohnson
karlrwjohnson / es-module-__dirname.md
Created February 23, 2023 23:09
Equivalent of __dirname in ES Modules

When converting a Node CommonJS module to an ES module, __dirname stops working.

Add this line to make it work again:

import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = dirname(fileURLToPath(import.meta.url));
@karlrwjohnson
karlrwjohnson / Connecting to Microk8s remotely.md
Last active March 4, 2024 22:40
Connecting to Microk8s remotely

Configuring Microk8s for remote access

In order to learn about Kubernetes, I've installed Microk8s on Ubuntu Server on an old laptop stashed in my basement. It seemed like a better option than Minikube because Microk8s actually claims to have auto-update. (I really want auto-update because I'm a developer - not ops. I set things up, but I'm bad at maintaining them day over day.)

I got it installed okay, but I ran into trouble connecting to it remotely. In my opinion, the documentation for doing this is SUPER CONFUSING for beginners.

@karlrwjohnson
karlrwjohnson / web-dev-without-toolchains.md
Last active May 31, 2023 06:31
Web Development without Toolchains

Web Development without Toolchains

Yelling at clouds

When I first started playing with web development, I was building toy websites with Microsoft FrontPage and ogling over the cool features on Dynamic Drive. It seemed like files were written by hand in text editors and published directly by copying them to FTP sites.

(Later I found out about PHP and server-rendered sites.)

@karlrwjohnson
karlrwjohnson / patch_pdf_bookmarks.py
Created April 12, 2021 00:22
Script to edit a PDF file's bookmarks using a text editor (uses pdftk-java and Python3)
#!/usr/bin/python3
##
## PDF Bookmark Patcher script
##
## This script allows you to use a regular text editor to edit the bookmarks
## in a PDF file. It is a wrapper around another tool called PDFtk-java.
##
## Usage:
## 1. < replace somefile.pdf with the name of your file >
## 2. python3 ../extract_bookmarks.py somefile.pdf --export-text bookmarks.txt
"""
Solution finder for puzzle in Legend of Zelda: Twilight Princess to obtain the Master Sword.
The temple is guarded by a pair of golems. When the player approaches, the ground transforms into a grid of squares.
As the player moves around the board, the golems move in response. The player must maneuver the two golems onto
two specific squares in order to proceed.
This Python script finds a solution in 801 iterations on a breadth-first search of all possible movements.
For some reason, I've annotated how it all works.
@karlrwjohnson
karlrwjohnson / simple-store.tsx
Created October 6, 2020 15:56
Alternative React data store (no action objects; dispatch reducers directly)
import {Dispatch, SetStateAction, useCallback, useLayoutEffect, useRef, useState} from "react";
/**
* Object that stores immutable data,
* allows components to subscribe to changes in that data,
* and exposes functions to update the state by mapping the previous state to a new state
*
* Similar to Redux, except instead of dispatching actions which are consumed by a reducer,
* it's like you dispatch the reducer functions themselves.
*
@karlrwjohnson
karlrwjohnson / kotlin-js-spa.md
Created September 1, 2019 18:51
Customizing Kotlin/JS's Webpack configuration

This is mostly notes to myself in case I ever do this again.

So, I've been doing a lot of frontend development in Typescript/React, but I'm also interested in Kotlin. I'm a full-stack engineer, so the idea of making a whole application in the same language appeals to me. (I'm aware that backend development in NodeJS exists, but I'm a fan of strict typing.)

So I've been exploring Kotlin's JS backend support.

So anyways, here's how my project is set up right now: