Skip to content

Instantly share code, notes, and snippets.

View predaytor's full-sized avatar
🍁
it's perfect

Dmytro Pushkarchuk predaytor

🍁
it's perfect
View GitHub Profile
@rodrigo-arias
rodrigo-arias / wpgraphql-non-public-post-tracker.md
Last active September 14, 2026 18:27
Tag WPGraphQL Smart Cache responses with non-public post IDs so draft→publish purges cached nulls — workaround for wp-graphql#4298

WPGraphQL Smart Cache: purge cached nulls when a draft is published

Workaround for wp-graphql#4298: a public query for a non-public post's URI caches a null response with no post:<id> tag in X-GraphQL-Keys, so publishing the post can never invalidate it — the query stays a HIT on stale null until TTL.

What it does

Tracks nodes that are resolved but not returned, without touching the security model (responses stay null; only the cache tag is added):

  1. graphql_resolve_uri — when NodeResolver found nothing, re-query with non-public statuses and feed the match through the post loader (its visibility gate still nulls it out).
  2. graphql_dataloader_pre_get_model — capture the IDs the loader filters out.
@jacob-ebey
jacob-ebey / use-list.ts
Last active January 26, 2026 08:12
useList hook for optimistic server action based modifications
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
@sergiodxa
sergiodxa / crud.ts
Last active July 28, 2026 06:25
A crud helper for RRv7 routes.ts file
import { index, prefix, route } from "@react-router/dev/routes";
import { camelize, pluralize, singularize } from "inflected";
function createCrud(base = "./views") {
/**
* Create a CRUD route configuration.
* @param name The name of the resource. It will be pluralized for the path.
* @param options The options for the crud.
* @param options.member Extra routes to add to each member.
* @param options.collection Extra routes to add to the collection.
import {
signal,
effect,
useSignal,
type useSignalEffect,
type Signal,
type ReadonlySignal,
} from '@preact/signals';
import { VNode, type ComponentChildren } from 'preact';
import {
import { Hono } from 'hono'
import type { Context } from 'hono'
interface ProxyFetch {
(
c: Context,
input: RequestInfo | URL,
modifyRequest: (req: Request) => void | undefined,
modifyResponse: (res: Response) => void | undefined
): Promise<Response>
@okikio
okikio / constrain-transform-stream-queues.md
Last active December 7, 2024 03:04
Queue's via TransformStreams

Using TransformStream in place of traditional queue implementations is an interesting approach that leverages the stream API's natural queuing and backpressure features. Below is a breakdown of how you might implement each queue type using TransformStream, adhering to the constraint of using no more than 2 TransformStreams per queue, and addressing any limitations that arise.

1. Simple Queue (FIFO Queue)

  • Implementation:
    • TransformStream 1: This stream simply passes data from the writable side to the readable side in FIFO order.
    • TransformStream 2: Not necessary in this case, as one TransformStream is sufficient to maintain the FIFO order.
const fifoQueue = new TransformStream(undefined, undefined, { highWaterMark: Infinity });
@rphlmr
rphlmr / index.ts
Last active April 13, 2025 14:59
Link XState and Remix fetcher
import type { ActionFunctionArgs, LoaderFunctionArgs } from '@remix-run/node';
import {
ClientActionFunctionArgs,
ClientLoaderFunctionArgs,
useFetcher,
useLoaderData,
} from '@remix-run/react';
import { enqueueActions, fromPromise, setup } from 'xstate';
import { useActor } from '@xstate/react';
import { useEffect, useRef } from 'react';
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = "my-app"
primary_region = "cdg"
kill_signal = "SIGINT"
kill_timeout = "5s"
swap_size_mb = 256
@VariableVic
VariableVic / google-analytics.ts
Last active May 29, 2025 05:56
Medusa -> Google Analytics 4 server side tracking example
import { TransactionBaseService } from "@medusajs/medusa";
import {
ConsentSettings,
EventItem,
JSONPostBody,
} from "../types/google-analytics";
const { subtle } = require("crypto").webcrypto;
@pilcrowonpaper
pilcrowonpaper / crypto-random-integer.ts
Last active January 6, 2024 23:21
Generates a random integer between 0 and a max number.
function generateRandomInteger(max: number): number {
if (max < 0 || !Number.isInteger(max)) {
throw new Error("Argument 'max' must be an integer greater than or equal to 0")
}
const bitLength = (max - 1).toString(2).length
const shift = bitLength % 8
const bytes = new Uint8Array(Math.ceil(bitLength / 8))
while (true) {
crypto.getRandomValues(bytes)
// This zeroes bits that can be ignored to increase the chance `result` < `max`.