Skip to content

Instantly share code, notes, and snippets.

View jonathanconway's full-sized avatar
⌨️
Typing

Jon jonathanconway

⌨️
Typing
View GitHub Profile
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
@jonathanconway
jonathanconway / unescape-format-selected-json-chrome.js
Last active October 1, 2026 02:10
Unescape and format selected JSON - Chrome bookmarklet
/**
* Unescape and format JSON selected in browser page - Chrome bookmarklet.
*
* Generated by Claude Code Opus 5.5 on 2024-06-19T15:30:00Z
*
* Prompts:
* - Is there a browser extension that allows me to select any region of a page that is JSON and formats it nicely (unescaping, indentation, syntax highlighting, etc) and shows it to me?
* - I got this error in the Javascript snippet: <error>. Can you help me fix it?.
* - Turn this into a small unpacked Chrome extension with a right-click "Format selected JSON" menu item, which works on those strict-policy sites too.
*/
@jonathanconway
jonathanconway / assert.ts
Last active July 24, 2026 05:25
Assertion helper function, to generate informative, type-safe assertions
export function assert(
condition: unknown,
message?: string
): asserts condition {
if (!condition) {
throw new AssertionViolationError(message);
}
}
export class AssertionViolationError extends Error {
@jonathanconway
jonathanconway / template-parser.ts
Last active June 3, 2026 12:05
Flexible template parser
/**
* Parses a templated expression for fields.
* Token opening and closing delimiters can be customised.
*/
function parseTemplate({
input,
tokenDelimiters: {
open,
close,
} = {
@jonathanconway
jonathanconway / delete-all-branches-except-main.sh
Created May 14, 2026 23:13
Bash script: Delete all branches except `main` in the current git repo
# Generated by AI.
# Prompt: Write a bash command that switches git to `main` branch and removes all git branches except `main`.
git checkout main && git branch | grep -v '^\* main$' | grep -v '^ main$' | xargs -r git branch -D
@jonathanconway
jonathanconway / browser-a11y-project-checklist-to-md.js
Last active April 28, 2026 11:07
A11yProject - Scrape checklist items and output as Markdown
/*
* Source: https://www.a11yproject.com/checklist/
*
* Output:
*
* #### Accessibility - Content
*
* - [ ] Use plain language and avoid figures of speech, idioms, and complicated metaphors.<br />[Article: WCAG - 3.1.5 READING LEVEL](https://www.w3.org/WAI/WCAG22/Understanding/reading-level.html)<br /> #nfr--accessibility #accessibility--content
* - [ ] Make sure that <code>button</code>, <code>a</code>, and <code>label</code> element content is unique and descriptive.<br />[Article: WCAG - ](https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships.html)<br /> #nfr--accessibility #accessibility--content
*
@jonathanconway
jonathanconway / conventional-commit.code-snippets
Last active April 24, 2026 00:53
VSCode Snippet - Conventional Commit Message
{
"Conventional Commit Message": {
"body": "${1|build,chore,ci,docs,feature,fix,performance,refactor,revert,style,test|}: ${2:ticket} ${3:message}",
"description": "Conventional commit message in the format: <type>: TICKET-123 descriptive message"
}
}
/**
* $1: type
* Source: https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional
const resolvedEls = document.querySelectorAll('[data-action="click:review-thread-collapsible#toggle"]');
resolvedEls.forEach(el => el.click())
@jonathanconway
jonathanconway / pascal-case.ts
Created March 17, 2026 03:26
Converts provided string to PascalCase
import { kebabCase, startCase } from "lodash";
/**
* Converts provided string to PascalCase
* @example my-string => MyString
* @example myString => MyString
* @example my_string => MyString
* @example MY_STRING => MyString
*/
export function pascalCase(input: string) {
@jonathanconway
jonathanconway / scripts.md
Last active April 18, 2026 06:53
Some handy shell commands for MacOS

Terminal

Increase the terminal buffer to 100kb so you can scroll up and see more output.

  • {command} is the command you want to run and see more output from
DEBUG_PRINT_LIMIT=100000; {command}