Skip to content

Instantly share code, notes, and snippets.

View aleclarson's full-sized avatar

Alec Larson aleclarson

View GitHub Profile
diff --git a/alias.js b/alias.js
index a2e9dddc6b19e5668d23b2b25a0718ee2a201c37..6d21587b4e771ffb406d6193d381076bc5c5f229 100644
--- a/alias.js
+++ b/alias.js
@@ -98,7 +98,7 @@ function mapColumnsInSQLToAlias(query, alias) {
return mapColumnsInAliasedSQLToAlias(c, alias);
}
return c;
- }));
+ })).mapWith(query.decoder);
@aleclarson
aleclarson / select-without-from.ts
Created June 24, 2025 18:38
An incomplete attempt at "SELECT without FROM" in Drizzle
import { sql, Subquery, WithSubquery, type SQL, type SQLWrapper } from 'drizzle-orm'
import type { SelectResultField } from 'drizzle-orm/query-builders/select.types'
type SelectResultFields<TSelectedFields extends Record<string, any>> = {
[K in keyof TSelectedFields]: TSelectedFields[K] extends SQLWrapper
? SelectResultField<TSelectedFields[K]>
: SQL<TSelectedFields[K]>
}
export function select<TAlias extends string, const TSelectedFields extends Record<string, any>>(
@aleclarson
aleclarson / 0. Local Development Script For Google Cloud Run Functions.md
Last active May 2, 2025 23:42
Multiple functions (with watch mode) for @google-cloud/functions-framework

With this gist, you can test multiple functions at a time. Functions are always loaded on-demand, so they're always up-to-date. TypeScript functions are supported out-of-the-box.

Pre-requisites

pnpm install esbuild -D

Usage

// ==UserScript==
// @name Replace Clip with Save on YouTube
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Replaces the Clip button with the Save button on YouTube video pages
// @author You
// @match https://www.youtube.com/*
// @grant none
// @source https://gist.github.com/aleclarson/60fc2c4fd9276ceba0063066a4e55ef8
// ==/UserScript==
@aleclarson
aleclarson / script.js
Last active February 8, 2025 19:56
YouTube feedback shortcut – TamperMonkey
// ==UserScript==
// @name YouTube Enhanced Interaction
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Enhanced click handling for YouTube recommendations
// @author You
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==

This gist is a further condensed version of https://svelte.dev/llms-small.txt from https://svelte.dev/docs/llms

Removed sections

These sections were removed to optimize the context window. Each section was deemed non-critical for MVP purposes or its use cases were deemed too niche. When developing a brownfield Svelte app, many of these sections should not be removed.

  • Overview
  • Getting Started
  • Accessibility
  • SEO
@aleclarson
aleclarson / query.pgsql
Last active November 25, 2024 19:55
Postgres – get public dependencies
SELECT DISTINCT
d.deptype,
from_table.relname AS classid,
COALESCE(from_class.relname, from_type.typname, from_proc.proname) AS objid,
from_attr.attname AS objsubid,
to_table.relname AS refclassid,
COALESCE(to_class.relname, to_type.typname, to_proc.proname, to_ext.extname, to_con.conname) AS refobjid,
to_attr.attname AS refobjsubid
import { withCapacity } from 'radashi'
export function keyedCapacity<TKey, TResult>(capacity: number) {
const queue = withCapacity(capacity)
const jobs = new Map<TKey, Promise<TResult>>()
return {
keys: (): IterableIterator<TKey> => jobs.keys(),
get: (key: TKey): Promise<TResult> | undefined => jobs.get(key),
run(key: TKey, job: () => Promise<TResult>): Promise<TResult> {
@aleclarson
aleclarson / mergeGenerators.ts
Created November 21, 2024 22:27
Combine one or more async generators in TypeScript
/**
* Merge multiple generators into a single generator.
*/
function mergeGenerators<T>(generators: AsyncGenerator<T>[]): AsyncGenerator<T>
/**
* Merge multiple generators into a single generator. Whenever a generator
* yields, the `{done, value}` object is passed to `mapResult` to transform the
* value that will be yielded.
/*
* API struct for a table AM. Note this must be allocated in a
* server-lifetime manner, typically as a static const struct, which then gets
* returned by FormData_pg_am.amhandler.
*
* In most cases it's not appropriate to call the callbacks directly, use the
* table_* wrapper functions instead.
*
* GetTableAmRoutine() asserts that required callbacks are filled in, remember
* to update when adding a callback.