Skip to content

Instantly share code, notes, and snippets.

View drenther's full-sized avatar
🏠
Working from home

Soumyajit Pathak drenther

🏠
Working from home
View GitHub Profile
@NuroDev
NuroDev / schedule-controller.ts
Created November 21, 2025 16:36
⏲️ Schedule Controller - A minimal `Hono` style controller for Cloudflare Workers scheduled handler
export interface ScheduleHandlerContext<E = Env> {
/**
* The scheduled event controller providing details about the cron trigger.
*/
controller: ScheduledController;
/**
* The environment bindings available to the worker.
*/
env: E;
/**
@mfrancis107
mfrancis107 / use-debounced-search-param.ts
Created November 6, 2025 15:20
Tanstack Search Param Debouncer
// src/routes/search/useDebouncedSearchParam.ts
import { useEffect, useMemo, useRef, useState } from 'react'
import { useDebouncedValue } from '@tanstack/react-pacer' // React adapter re-exports
// Alternative import also works in examples: '@tanstack/react-pacer/debouncer'.
// See Pacer React adapter docs. :contentReference[oaicite:5]{index=5}
type RouteSearchFrom<RouteApi> = RouteApi extends { types: { fullSearchSchema: infer TSchema } }
? TSchema extends Record<string, unknown>
? TSchema
: Record<string, unknown>
// Turn all HTML <a> elements into client side router links, no special framework-specific <Link> component necessary!
// Example using the Next.js App Router.
import { useRouter } from 'next/navigation';
import { useEffect } from 'react';
function useLinkHandler() {
let router = useRouter();
useEffect(() => {
let onClick = e => {

This middleware does a few interesting things:

  • Ensures a url shape in the zustand store, where we'll store URL information.
  • Assumes we will be storing our url state slice in the ?state search parameter after it has been stringified and base 64 encoded.
  • On creation, decodes stores state from the ?state search parameter into the url slice of our store.
  • After each state update, updates the ?state search parameter with the new url state slice.
  • Sets up an event listener that listens for popstate and re-decodes the state from the URL into our store.
name: PlanetScale Migration
on:
pull_request:
types: [opened, synchronize]
paths:
- packages/shared/adapters/prisma/schema.prisma
env:
PLANETSCALE_ORG: flightcontrol
PLANETSCALE_DB: fc-production
import invariant from "tiny-invariant";
class AmalgoBox extends HTMLElement {
get input() {
return this.querySelector("input") as HTMLInputElement;
}
get button() {
return this.querySelector("button") as HTMLButtonElement;
}
@rauschma
rauschma / README.md
Last active May 10, 2023 09:53
Better dynamic type checks

Better dynamic type checks

  • Update 2022-07-10: new approach based on Function.prototype.hasInstance()

Problems

In principle, the rule “typeof is for primitive values, instanceof is for objects” works. There are two exceptions:

  • Checking if a value is an object
  • Cross-realm instance checks
import { withAuthUserTokenSSR, AuthAction, type AuthUser } from "next-firebase-auth";
import { NextApiRequest, NextApiResponse } from "next";
const checkServerSideAuth =
typeof window !== "undefined"
? () => {} // "withAuthUserTokenSSR" can only be called server-side.
: withAuthUserTokenSSR({
whenAuthed: AuthAction.RENDER,
whenUnauthed: AuthAction.REDIRECT_TO_LOGIN,
authPageURL: "401",
@steveruizok
steveruizok / usePublishCallback.ts
Created September 23, 2021 16:34
Croquet.io React Bindings (requires @croquet/react and @croquet/croquet)
import * as React from "react"
import { Model } from "@croquet/croquet"
import { CroquetContext } from "@croquet/react"
/**
* A callback that publishes the returned data to the current view's model.
* @param eventName The name of the event to be published.
* @param fn A function that returns the data to be published.
* @param deps (optional) An array of dependencies for the callback.
*/
@gragland
gragland / App.js
Last active March 5, 2024 20:05
How to lazy load Firebase with dynamic imports
import getFirebase from "./firebase.js";
function MyApp() {
// Example function that wraps some firebase logic
const onSignup = async (email, password) => {
// Use await to ensure firebase library is loaded
const firebase = await getFirebase();
// Call firebase methods as you normally would
const { user } = await firebase.auth()
.createUserWithEmailAndPassword(email, password);