Skip to content

Instantly share code, notes, and snippets.

View benjie's full-sized avatar

Benjie benjie

View GitHub Profile
@benjie
benjie / multisuffix.js
Last active May 19, 2025 11:08
GitHub pull request JS snippet to mark all ".mermaid" files as viewed (substitute for any file extension)
((suffixes) => {let skip = 0; let abort = false; [...$$(suffixes.map(suffix => `a[title$="${suffix}"]`).join(','))].map(el => {const checks = el.parentNode.parentNode.parentNode.querySelectorAll('.js-reviewed-checkbox');if (checks.length !== 1) { throw new Error("Script out of date?");} return checks[0]}).forEach((inpt, i) => inpt.checked ? ++skip : setTimeout(() => {if (abort) return; inpt.click();}, (i - skip) * 1000))})([".mermaid",".export.mjs"])
a = () => () => () => 2;
console.log(a``````);

PostGraphile reproduction script

Hello, you've probably been sent here because you've found an issue in your usage of PostGraphile. I (Benjie) deal with a lot of support requests that have insufficient information for me to diagnose the problem, so I'll ask for a minimal reproduction. Making a minimal reproduction allows me to diagnose (and potentially fix!) the issue much more easily, and is also a valuable exercise for you during your debugging - who knows, maybe whilst attempting to create the reproduction you'll figure out what went wrong and fix your own issue?

To use this, please download the script locally, and then populate the DATABASE

@benjie
benjie / swc.js
Last active August 25, 2024 22:42
A script for running SWC in a monorepo that uses TypeScript project references (`tsc --build` / `tsc -b`) compiling everything in parallel with optional watch mode. For this to work you MUST have `isolatedModules: true`.
const swc = require("@swc/core");
const chokidar = require("chokidar");
const glob = require("glob");
const { promises: fsp } = require("fs");
const { basename, dirname } = require("path");
const { createHash } = require("crypto");
const mkdirp = require("mkdirp");
const WATCH = process.argv[2] === "--watch";
#!/usr/bin/env bash
set -e
# What DB are we messing with? (THIS DB WILL BE OVERWRITTEN!)
DATABASE="timethor"
SCHEMA="main"
# Populate database
dropdb --if-exists "$DATABASE"
createdb "$DATABASE"
import { Plugin } from 'postgraphile';
/**
* Allows you to override the default orderBy for a given field to be the
* orderBy with the given name. Usage:
*
* ```
* const MyOrderByPlugin = makeSetDefaultOrderByForFieldPlugin(
* 'MyTableName',
* 'myRelationName',
@benjie
benjie / strip_tags_from_introspection.js
Created May 21, 2021 15:24
A Graphile Engine plugin to strip all tags/descriptions from introspection results
module.exports = (builder) => {
builder.hook("build", (build) => {
const oldPgAugmentIntrospectionResults =
build.pgAugmentIntrospectionResults;
build.pgAugmentIntrospectionResults = (inIntrospectionResult) => {
let pgIntrospectionResultsByKind = inIntrospectionResult;
if (oldPgAugmentIntrospectionResults) {
pgIntrospectionResultsByKind = oldPgAugmentIntrospectionResults(
pgIntrospectionResultsByKind,
);
const symbols = [];
for (let i = 0; i < 1000; ++i) {
symbols[i] = Symbol(`key_${i}`);
//symbols[i] = `key_${i}`;
}
function test1() {
const map = new Map();
for (let i = 0; i < 10000; ++i) {
SELECT
pg_size_pretty(total_bytes) AS total,
pg_size_pretty(index_bytes) AS index,
pg_size_pretty(toast_bytes) AS toast,
pg_size_pretty(total_bytes - index_bytes - toast_bytes) AS table
FROM (
SELECT
pg_total_relation_size(c.oid) AS total_bytes,
pg_indexes_size(c.oid) AS index_bytes,
coalesce(pg_total_relation_size(reltoastrelid), 0) AS toast_bytes
@benjie
benjie / loop_perf.js
Last active June 4, 2021 13:58
Comparing loop method performance in JS
const arr = [];
const ARRAY_SIZE = parseInt(process.argv[2], 10) || 10;
const RUNS = Math.ceil(1000000000 / ARRAY_SIZE);
console.log(`Performing ${RUNS} runs of arrays with ${ARRAY_SIZE} elements`);
for (let i = 0; i < ARRAY_SIZE; i++) arr[i] = i;
function runTest(name, testFunction) {
if (global.gc) global.gc();