Skip to content

Instantly share code, notes, and snippets.

@codebutler
codebutler / preevy-down.yml
Last active March 25, 2024 23:11
preevy + s3 + k8s
name: Teardown Preevy environment
on:
pull_request:
types:
- closed
permissions:
# Needed to authenticate with AWS
id-token: write
# Needed to read the docker-compose.yml file
// example of how to run prettier from orval.config.ts
import fs from "fs/promises";
import * as prettier from "prettier";
import path from "path";
const walk = async (inputPath: string): Promise<string[]> => {
const stats = await fs.stat(inputPath);
if (!stats.isDirectory()) {
return [inputPath];
import { Project, SyntaxKind } from "ts-morph";
/**
* This script converts all "barrel" imports to fully qualified imports.
*
* Use 'bun' to run the script:
* bun run morphs/fully-qualified-gen-imports.ts
*/
const project = new Project({

Proposal for OpenAPI Custom Extension: Automated Client-Side Cache Invalidation

Extension Name: x-cache-invalidates-operation-ids

Purpose

The x-cache-invalidates-operation-ids extension is designed for use in auto-generated client-side code, facilitating automated cache invalidation based on operation interactions. This extension allows API designers to specify operation IDs that should trigger cache invalidation in the client's local cache, ensuring data consistency and up-to-date information in client applications.

Usage

Applied within the paths section of an OpenAPI document, this extension targets individual API operations. It specifies which operations, identified by their operationId, should have their cache invalidated upon the execution of a given operation.

# Extends drf serialization to support union types without any additional boilerplate.
# See test for example usage.
#
# From https://drf-spectacular.readthedocs.io/en/latest/blueprints.html:
# Simply copy&paste the snippets into your codebase. The extensions register
# themselves automatically. Just be sure that the python interpreter sees them
# at least once. To that end, we suggest creating a PROJECT/schema.py file and
# importing it in your PROJECT/__init__.py (same directory as settings.py and urls.py)
# with import PROJECT.schema. Now you are all set.
@codebutler
codebutler / ts-morph-i18next-keys-to-camel-case.ts
Created October 27, 2023 19:12
Script that converts i18next/i18next-react translation keys from snake_case to camelCase
import * as fs from "fs";
import { camelCase } from "lodash";
import * as path from "path";
import { Node, Project, SyntaxKind } from "ts-morph";
/*
* This script converts all i18next/i18next-react translation keys from
* snake_case to camelCase. It updates the JSON translation files and the
* source code.
*
import { ImportDeclaration, Project, SourceFile, SyntaxKind } from "ts-morph";
/*
* This script uses ts-morph to convert all (react-router-dom) routes to be lazy.
* It also updates all route components to be exported by name rather than as default.
*
* This script is not very robust and will probably need some tweaking to work with your
* code, but hopefully its a helpful starting point.
*
* Run with:
/*
Generates typesafe-routes code for all routes in the app.
See the typesafe-routes docs for information on how to use it:
https://github.com/kruschid/typesafe-routes
Usage:
pnpm vite-node buildSrc/typesafe-routes-gen.ts
Authors:
@codebutler
codebutler / api.ts
Created March 23, 2023 20:49
String array query parameters with axios + django-rest-framework
const api = axios.create({
// other options...
paramsSerializer: {
// drf expects array params to be repeated, e.g. ?foo=bar&foo=baz
// the default behavior is to serialize them as foo[]=bar&foo[]=baz
serialize: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
},
});
@codebutler
codebutler / Icons.mdx.txt
Last active March 14, 2023 20:03
Storybook dynamic auto-generated icon gallery
import { IconGallery, IconItem, Meta } from "@storybook/blocks";
import React from "react";
export const icons = import.meta.glob("../shared/icons/*.tsx", { eager: true });
<Meta title="Documentation/Icons" />
# Icons
<IconGallery>