Skip to content

Instantly share code, notes, and snippets.

@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:

#!/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')