Skip to content

Instantly share code, notes, and snippets.

View itsjohncs's full-sized avatar

John Sullivan itsjohncs

View GitHub Profile
@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 <johnsullivan.pem@gmail.com>
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>
@itsjohncs
itsjohncs / when-no-chess.py
Created March 4, 2021 04:41
When ran against your chess data export from Lichess, prints out the dates during which you played no games.
#!/usr/bin/env python3
import re
import datetime
played_chess_on = set()
with open("/Users/johnsullivan/Downloads/lichess_johncs_2021-03-04.pgn") as f:
for line in f:
match_obj = re.match(r'^\[Date "([^"]+)"]\s*$', line)
if match_obj: