Skip to content

Instantly share code, notes, and snippets.

View gaving's full-sized avatar
🎯
Focusing

Gavin Gilmour gaving

🎯
Focusing
View GitHub Profile
@gaving
gaving / transform-add-any-to-apollo-hooks.js
Created August 26, 2025 17:17
A codemod that adds missing generic <any> types to untyped Apollo hooks
// Patch ANY untyped Apollo-ish hooks: useQuery/useLazyQuery (<any>), useMutation (<any, any>)
// regardless of import origin (direct, re-exports, namespace, etc.)
module.exports.parser = "tsx";
module.exports = function transformer(file, api) {
const j = api.jscodeshift;
const root = j(file.source);
const HOOKS = {
useQuery: { arity: 1 },
@gaving
gaving / transform-cast-client-query-to-tdn.js
Created August 26, 2025 17:12
A codemod that adds TypedDocumentNode<any, any> typing to Apollo query and mutate calls
// Robust patcher for Apollo Client calls:
// - Edits client.query({...}) and client.mutate({...})
// - If options arg is an ObjectExpression, casts its `query:` or `mutation:` value to
// `TypedDocumentNode<any, any>` and inserts a type-only import.
// - If options arg is an Identifier bound to an object literal in the same file, edits that.
// - Otherwise, falls back to adding generics to the call: <any, any>
// Works with awaited and non-awaited calls. Also tolerates optional chaining.
// Run with: --parser=tsx --extensions=ts,tsx
module.exports.parser = "tsx";
@gaving
gaving / transform-gql-to-graphql.js
Last active August 26, 2025 17:14
A codemod that converts gql to graphql and fixes related imports
/**
* Usage:
* npx jscodeshift -t transform-gql-to-graphql.js src \
* --extensions=ts,tsx,js,jsx --gitignore \
* --graphqlImportPath=@/gql
*
* Options:
* --graphqlImportPath=../gql Path to your generated helper (default ../gql)
*
* What it does:
@gaving
gaving / pluralize.js
Created February 6, 2024 08:31
pluralize
function pluralize(count, word) {
// Basic pluralization rules
const pluralRules = [
{ match: /(?:ch|sh|ss|x|z)$/, replace: "$&es" }, // Matches words ending in ch, sh, ss, x, z
{ match: /([^aeiou])y$/, replace: "$1ies" }, // Changes words ending in y preceded by a consonant to ies
{ match: /([^aeiou])o$/, replace: "$1oes" }, // Changes words ending in o preceded by a consonant to oes (e.g., hero to heroes)
{ match: /is$/, replace: "es" }, // Special case for words ending in is
{ match: /([^aeiou]o)$/, replace: "$1es" }, // Special case for words ending in o preceded by a consonant
// Add more rules as needed
];
@gaving
gaving / install.log
Last active January 12, 2023 16:35
win32yank latest build
Compiling proc-macro2 v1.0.49
Compiling quote v1.0.23
Compiling unicode-ident v1.0.6
Compiling syn v1.0.107
Compiling winapi-x86_64-pc-windows-gnu v0.4.0
Compiling libc v0.2.139
Compiling serde_derive v1.0.152
<jemalloc>: MADV_DONTNEED does not work (memset will be used instead)
<jemalloc>: (This is the expected behaviour if you are running under QEMU)
<jemalloc>: MADV_DONTNEED does not work (memset will be used instead)
mdl . | ( grep -v "Kramdown Warning: No link definition for link ID '\[\?_toc_\]\?' found on line" || true )
@gaving
gaving / README.md
Last active January 19, 2021 19:53
import-icons-by-path

Description

Convert Material UI icons to path imports. E.g.

-import { ErrorOutline as ErrorIcon } from "@material-ui/icons";
+import ErrorIcon from "@material-ui/icons/ErrorOutline";

Reasoning:-

@gaving
gaving / README.md
Last active January 19, 2021 19:38
convert-to-absolute-imports

Description

Convert Material UI icons to path imports. E.g.

-import DashboardTitle from "../../../components/Dashboard/DashboardTitle";
+import DashboardTitle from "components/Dashboard/DashboardTitle";

Reasoning:-

@gaving
gaving / index.html
Created January 2, 2021 09:24
Type The TOS
<div class="tos-wrapper">
<h1 class="title">TOS</h1>
<div id="count"></div>
<div id="tos"></div>
</div>

Keybase proof

I hereby claim:

  • I am gaving on github.
  • I am gaving (https://keybase.io/gaving) on keybase.
  • I have a public key ASAus1flHDIEFaLySFtJhm8D-LbShQcRlNkmqf87GlgKHQo

To claim this, I am signing this object: