Skip to content

Instantly share code, notes, and snippets.

View agwells's full-sized avatar

Aaron Wells agwells

View GitHub Profile
@agwells
agwells / readme.txt
Created January 7, 2026 23:18
Transition (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@agwells
agwells / readme.txt
Created January 7, 2026 23:11
Transition (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@agwells
agwells / readme.txt
Created January 2, 2026 21:33
i herd u liek water templs (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@agwells
agwells / readme.txt
Created January 2, 2026 21:28
i herd u liek water templs (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@agwells
agwells / gist:7068d4ce3d94aebcf57bef2993ec5b23
Last active August 15, 2025 01:09
Tiny seedable PRNG in JavaScript
/**
* A lightweight seedable RNG for generating low-quality random numbers.
*
* I find this mostly useful in testing and Storybook, where I want to
* repeatably generate a sequence of random numbers, but I don't need
* cryptographically strong randomness. It's only useful in those
* circumstances. Otherwise...
*
* - If it doesn't need to be repeatable, just use JS's native "Math.random()"
* - If it needs to be cryptographically strong, import a reliable PRNG package
@agwells
agwells / gist:bd3f237879a39e76f12a0cb42f1c2fcf
Last active August 1, 2021 22:29
Manually setting up an npm auth token (without using `npm login`)

I was annoyed to find tha the NPM website lets you generate auth tokens manually, but does not provide any instructions on how to configure them in your local workspace. The only instructions are to give your username and password to npm login, which will then configure our workspace.

But all npm login does is pop the token into some annoyingly undocumented config fields in ~.npmrc. You can just as easily do this manually, if you would rather not type your password into a terminal script.

  1. Log in to the NPM website and generate an auth token.
  2. Put it in your ~/.npmrc file like so:
//registry.npmjs.org/:_authToken=YOUR-TOKEN-WOULD-GO-HERE
@agwells
agwells / webpack.cra-ssr.js
Created February 19, 2020 10:35
Webpack config to compile Create React App code to execute in Node
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const NodemonPlugin = require('nodemon-webpack-plugin');
// Directory the compiled SSR server and assets will go in
const SSR_BUILD_PATH = './ssr-build'
const originalNodeEnv = process.env.NODE_ENV;
// This must be "production" for the CRA webpack config to be correct.
@agwells
agwells / cracli.js
Last active September 30, 2019 21:17
Executing code written for Create React App, as a CLI
/**
* This file is the "Launch" script for running Create React App code at the command
* line. It calls "@babel/register", which is a Babel utility that hijacks
* the normal node "require()" function and lets Babel pre-compile imported
* files into Node-compatible JS before they're executed.
*
* This bootstraps up the fancy CRA TypeScript/React configuration (using the
* Babel config imported from "babel-preset-react-app"). Then it simply "require()"s
* some other JS/TS/JSX/TSX file, and executes it.
*
@agwells
agwells / jestFailOnConsoleMessages.js
Created December 24, 2018 00:02
Make Jest tests fail if tests emit any console messages
// Fail the test if it prints ANYTHING to the console!
//
// Warning & log messages in test output are an anti-pattern. Also, testing
// for console messages is the only way to check for PropTypes failures
// (because all PropTypes does is print a console warning)
const realConsole = global.console;
// TODO: It's possible that some of the functions under global.console may
// have legitimate uses during test runs. If so, we'll need to be more picky.
global.console = Object.keys(realConsole).reduce(
@agwells
agwells / jestExpectAlwaysFail.js
Last active January 9, 2022 18:45
Programmatically fail a Jest test
/**
* Sometimes you want to programmatically force a Jest test failure. For example, mocking "console.warn()" to
* make tests fail if they print warning messages to the console. Throwing an error isn't sufficient, because
* the calling code may be in a try/catch block.
*
* Jest has no "fail()" method** to automatically trigger a test failure, but you can do it with an "expect()" matcher
* that will always fail, such as "expect(true).toBe(false)". This will fail the test, but the output isn't very
* self-explanatory. You can improve on it by providing a message string as one of the arguments:
* "expect(null).toBe('Automatic Failure!')". This is better, but the output is still a little confusing, saying
* it expected "null" and received "Automatic Failure!"