Skip to content

Instantly share code, notes, and snippets.

@sawyerh
sawyerh / good-code.md
Created October 25, 2026 00:45
What Good Code Looks Like

What Good Code Looks Like

My personal software engineering philosophy:

Good code is understandable first. It's broken into right-sized pieces that each do one clear thing, explains why rather than how, and earns every abstraction it introduces. Because it's understandable and loosely coupled, it can be verified, changed, or deleted without fear — and it doesn't make the user pay for the author's convenience, in what it ships or in what it runs.

That is the short version. The longer version is below.


@sawyerh
sawyerh / file-extensions.test.ts
Last active November 17, 2021 18:28
Test to disallow .js files
import path from "path";
import recursiveReadSync from "recursive-readdir-sync";
type RelativeFilePath = string;
type AbsoluteFilePath = string;
const SRC_DIR = "../src/";
const STORIES_DIR = "../storybook/stories/";
/**
@sawyerh
sawyerh / machine.js
Last active June 27, 2021 17:54
Machine - Routing using state machines
// machine.js
import { Machine } from "xstate";
// Conditions for some of our transitions
const guards = {
hasJobIncome: (context) => context.has_job_income === true,
};
export const routingMachine = Machine({
// Initial state is mostly useful for visualizations, for our purposes.
@sawyerh
sawyerh / machine.js
Last active June 27, 2021 17:52
Generated by XState Viz: https://xstate.js.org/viz
const routes = {
auth: {
login: "/auth/login",
reset: "/auth/reset-password"
},
apply: {
documents: "/apply/upload-docs",
income: "/apply/income",
name: "/apply/name",
review: "/apply/review",
@sawyerh
sawyerh / IncomePage.jsx
Last active June 27, 2021 18:14
Page - Routing using state machines
import { getNextPathname, goTo } from "router";
import { updateApplication } from "api";
function IncomePage() {
// This is within the page for example purposes, but
// could be abstracted for a multi-page form.
const handleFormSubmit = (event) => {
event.preventDefault();
const formData = new FormData(event.target);
@sawyerh
sawyerh / routes.js
Created June 27, 2021 17:32
Routes.js: Routing using state machines
// routes.js
export const routes = {
apply: {
documents: "/apply/upload-docs",
household: "/apply/household",
income: "/apply/income",
name: "/apply/name",
review: "/apply/review",
success: "/apply/success"
@sawyerh
sawyerh / router.js
Last active June 27, 2021 18:11
Router.js: Routing using state machines
// router.js
import { routingMachine } from "machine";
export function getNextPathname(event, context) {
const currentPathname = window.location.pathname;
const nextPathname = routingMachine
.withContext(context) // https://xstate.js.org/docs/guides/context.html
.transition(currentPathname, event); // https://xstate.js.org/api/interfaces/statemachine.html#transition
@sawyerh
sawyerh / nameParts.js
Last active January 1, 2021 20:36
Names of American novelists (a little over 2k)
var names = [
"patricia", "aakhus", "atia", "abawi", "edward", "abbey", "lynn", "belle", "kendrick", "abbott", "eleanor", "hallowell", "hailey", "megan", "shana", "abé", "louise", "abeita", "robert", "abel", "aberjhani", "walter", "abish", "abiola", "abrams", "diana", "susan", "abulhawa", "kathy", "acker", "cherry", "adair", "alice", "adams", "henry", "yda", "addis", "kim", "addonizio", "george", "ade", "renata", "adler", "warren", "james", "agee", "charlotte", "agell", "kelli", "russell", "agodon", "conrad", "aiken", "hiag", "akmakjian", "mitch", "albom", "kathleen", "alcalá", "louisa", "may", "alcott", "isabella", "macdonald", "alden", "clifford", "lindsey", "alderman", "thomas", "bailey", "aldrich", "malin", "alegria", "lloyd", "alexander", "sherman", "alexie", "horatio", "nelson", "algren", "hervey", "allen", "isabel", "allende", "dorothy", "allison", "lisa", "alther", "joseph", "altsheler", "julia", "alvarez", "rudolfo", "anaya", "laurie", "halse", "anderson", "poul", "sherwood", "eliza", "frances", "a
@sawyerh
sawyerh / SketchSystems.spec
Last active September 9, 2020 17:08
InputPii
InputPii
Empty*
onFocus -> Unmasked & Focused
Unmasked & Focused
onBlur -> Unmasked
Submit -> Masked
Unmasked
onFocus -> Unmasked & Focused
Masked
onFocus -> Masked & Focused
@sawyerh
sawyerh / SketchSystems.spec
Last active August 31, 2020 20:27
Verify ID step states
Verify ID step states
Not started
Answer some questions -> In Progress
In Progress
Answer all questions -> Completed
Completed
Review and confirm -> Submitted
Submitted