Skip to content

Instantly share code, notes, and snippets.

View itsjohncs's full-sized avatar

John Sullivan itsjohncs

View GitHub Profile
@itsjohncs
itsjohncs / parsing.ts
Created February 8, 2025 02:25
Dice roller parsing in Shmeppy
type Token =
| {type: "slash"; text: "/"}
| {type: "whitespace"; text: string}
| {type: "reason-delimiter"; text: ":"}
| {type: "reason"; text: string}
| {type: "operator"; text: "+" | "-"}
| {type: "roll"; text: string; sides: number; count: number};
export function lex(raw: string): Token[] | undefined {
if (!raw.startsWith("/")) {
@itsjohncs
itsjohncs / isTokenInRegion.ts
Created February 7, 2024 00:48
Efficient Detection of Collision between Ellipse and Many Squares
/**
* Creates a corner rect.
*
* `Rect` has slightly different semantics and isn't as suitable for inclusive
* `GridPoint` rectangles like were dealing with here.
*/
function createGridAlignedRect(
position: GridPoint,
width: number,
height: number
commit 1fea5d213b25f7bf8a9bef405ef2e4a22bd2dfa3
Author: itsjohncs <[email protected]>
Date: Tue Nov 2 01:27:12 2021 -0700
wip
diff --git a/client/components/Message.vue b/client/components/Message.vue
index 4b3e5887..d6627a8f 100644
--- a/client/components/Message.vue
+++ b/client/components/Message.vue
#!/usr/bin/env bash
set -euo pipefail
mapfile -t RESULT < <(
xargs -0r printf "%s\n" |
git check-ignore --non-matching --stdin --verbose |
grep "^::" |
cut -c 4-
)
type Point = [number, number] & {__brand?: any};
type GridPoint = Omit<Point, "__brand"> & {__brand?: "GridPoint"};
type PixelPoint = Omit<Point, "__brand"> & {__brand?: "PixelPoint"};
const point: Point = [1, 2];
const gridPoint: GridPoint = [1, 2];
const pixelPoint: PixelPoint = [1, 2];
// Points receive all
@itsjohncs
itsjohncs / bash-alias.sh
Created October 8, 2021 02:43
Copies the file name of the next modified file in a git repo, or the next untracked file if there's no modified files.
function gn {
printf 'Copied "'
( git ls-files -m; git ls-files -o ) | head -n 1 | tr -d '\n' | tee >(pbcopy)
printf '"\n'
}
@itsjohncs
itsjohncs / ExclusivelyModel.ts
Created October 6, 2021 19:29
An attempt at simulating an Exact data type in TS using existing tools.
// If all of Candidate's properties also exist in Model, this will be
// equivalent to Model. However, if Candidate has extra properties, they will
// be retyped to never and then merged into the resulting type.
//
// >>> ExclusivelyModel<{}, {a: number}>
// ... {a: number}
// >>> ExclusivelyModel<{a: number, b: number}, {a: number}>
// ... {a: number, b: never}
// >>> ExclusivelyModel<{a: string, b: number}, {a: number}>
// ... {a: number, b: never}
@itsjohncs
itsjohncs / hacky-code-mod.py
Created September 23, 2021 23:36
Adds a .js extension to all your imports!
#!/usr/bin/env python3
import re
import sys
import os
import_re = re.compile(r'^(import .*|}) from "(\.\.?/[^"]+)";?$', re.MULTILINE)
target_file = sys.argv[1]
@itsjohncs
itsjohncs / freezes.htm
Created September 17, 2021 01:21
One works and the other freezes the browser... Why?
<!DOCTYPE html>
<html>
<head>
<script>
let _openCVPromise = null;
function getOpenCV() {
if (_openCVPromise === null) {
_openCVPromise = new Promise(function(resolve, reject) {
const script = document.createElement("script");
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Solarized (light)</string>
<key>settings</key>
<array>
<dict>
<key>name</key>