Skip to content

Instantly share code, notes, and snippets.

@karlrwjohnson
karlrwjohnson / Taylor Cardsmith.txt
Created January 14, 2019 18:54
Taylor Cartsmith
Beastsoul Monk 1 / Armored & Gifted Blade (Soulknife) 4
STR 10 = ( 0p) 10
DEX 14 = ( 5p) 14
CON 14 = ( 5p) 14
INT 8 = (-2p) 8
WIS 20 = (17p) 18 + (Hu) 2
CHA 10 = ( 0p) 10
Level 1: Beastsoul Monk 1
@karlrwjohnson
karlrwjohnson / httpProxy.js
Created February 19, 2019 22:44
Quickie proxy that logs requests while forwarding to another service
const http = require('http');
const destHost = 'localhost';
const destPort = 4002;
http.createServer((req, res) => {
console.log(`> ${req.method} ${req.url}`);
for (let k in req.headers) {
console.log(`> ${k} = ${req.headers[k]}`)
}
@karlrwjohnson
karlrwjohnson / createReducer.ts
Created April 19, 2019 18:24
Type-safe reducer builder
/*
createReducer() builds a reducer function using an initial state and a map of reducer functions.
Any action whose type matches a key in the reducer map will cause createReducer()'s return value to invoke a method in the reducer map.
If you annotate your dispatch() function as DispatchFor<yourReducerHere>, it will prevent you from passing an event that it's incapable of handling.
*/
import { Action } from 'redux';
// Define an action whose metadata is stored in its "payload" field.
interface PayloadAction<K, P> extends Action<K> {
#!/usr/bin/env python3.6
BOX_CHARS = list(' ▘▝▀▖▌▞▛▗▚▐▜▄▙▟█')
BOX_PIXEL_ORDER = ((0,0), (1,0), (0,1), (1,1))
from argparse import ArgumentParser
from PIL import Image
from subprocess import Popen, PIPE
parser = ArgumentParser('Image to block character converter')
@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:

@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.
*
"""
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 / 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
@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 / 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.