Skip to content

Instantly share code, notes, and snippets.

View mpellegrini's full-sized avatar

Michael Pellegrini mpellegrini

View GitHub Profile
@mediacutlet
mediacutlet / HA_Voice_Shuffle_Plex.yaml
Last active April 20, 2025 15:29
Home Assistant Script to Enable LLM Voice Assistants to Shuffle Plex TV Shows
sequence:
- variables:
tv_show_query: " { other_tv_show_title } "
- if:
- condition: or
conditions:
- condition: state
entity_id: media_player.living_room
state: "off"
- condition: state
@zxt-tzx
zxt-tzx / json.ts
Last active May 7, 2025 11:53
Drizzle helper functions: json.ts
import type { AnyColumn, SQL, Table } from "drizzle-orm";
import { sql } from "drizzle-orm";
import type { PgColumn } from "drizzle-orm/pg-core";
import { type SelectedFields } from "drizzle-orm/pg-core";
import { type SelectResultFields } from "drizzle-orm/query-builders/select.types";
import { jsonBuildObject } from "./external-utils";
import type {
ExtractColumnData,
PathsToStringProperty,
@zxt-tzx
zxt-tzx / explain.ts
Last active May 7, 2025 11:55
Drizzle helper functions: explain
import type { SQLWrapper } from "drizzle-orm";
import { sql } from "drizzle-orm";
import type { DbClient } from "@/db";
export const explainAnalyze = async <T extends SQLWrapper>(
db: DbClient,
query: T,
) => {
const debugResult = await db.execute(sql`EXPLAIN ANALYZE ${query.getSQL()}`);
@zxt-tzx
zxt-tzx / conflict.ts
Created February 17, 2025 11:05
Drizzle helper functions: handling conflicts
import type { SQL, Table } from "drizzle-orm";
import { getTableColumns, sql } from "drizzle-orm";
// from https://github.com/drizzle-team/drizzle-orm/issues/1728
export function conflictUpdateAllExcept<
T extends Table,
E extends (keyof T["$inferInsert"])[],
>(table: T, except: E) {
const columns = getTableColumns(table);
const updateColumns = Object.entries(columns).filter(
@dvins
dvins / pnpm-peerdependency-override.md
Last active February 24, 2025 00:53
Overriding A Peer Dependency With PNPM

Overriding A Peer Dependency With PNPM

This guide explains how to override peer dependencies in a PNPM monorepo by using a custom hook. It provides a step-by-step solution to ensure consistent versioning across packages that rely on different versions of the same dependency.

Background

When working with a monorepo a challenges arises if you need to use multiple versions of the same package.

Nominally, this can be solved through package aliases and overides. However, a particularly sticky situation is when downstream packages rely peer dependencies of uptstream packages you need two or more versions of.

@EdamAme-x
EdamAme-x / mergeRoutes.ts
Created July 17, 2024 09:29
Hono MergeRoutes
import { Hono } from 'hono';
import type { MergeSchemaPath, MergePath, Env, Schema } from 'hono/types';
export interface Module {
path: string
routes: Hono
}
export function mergeRoutes<T extends Module[], H extends Hono>(base: H, ...routes: T) {
for (const route of routes) {
@rphlmr
rphlmr / clear-db.ts
Last active April 22, 2025 18:38
Drizzle snippets
// Credits to Louistiti from Drizzle Discord: https://discord.com/channels/1043890932593987624/1130802621750448160/1143083373535973406
import { sql } from "drizzle-orm";
const clearDb = async (): Promise<void> => {
const query = sql<string>`SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_type = 'BASE TABLE';
`;
@PabloSzx
PabloSzx / test-esm.mjs
Created August 12, 2021 16:45
Quick test Node.js ESM
// Using:
// [email protected]
// [email protected]
import globby from 'globby';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import chalk from 'chalk';
async function main() {
@Alia5
Alia5 / cheatsheet.ts
Last active October 25, 2024 07:19
Advanced Typescript Cheatsheet
export type Await<T> = T extends PromiseLike<infer U> ? Await<U> : T;
export type IsPromise<T> = PromiseLike<infer U> ? true : false;
export type Length<T> = T extends { length: infer L } ? L : never;
export type KeysOfType<O, T> = {
[K in keyof O]: O[K] extends T ? K : never;
}[keyof O];
// ConvertLiterals would convert literal types like `1337` to their base type like `number` if set to true
/** Used by Flavor to mark a type in a readable way. */
export interface Flavoring<FlavorT> {
_type?: FlavorT;
}
/** Create a "flavored" version of a type. TypeScript will disallow mixing flavors, but will allow unflavored values of that type to be passed in where a flavored version is expected. This is a less restrictive form of branding. */
export type Flavor<T, FlavorT> = T & Flavoring<FlavorT>;
/** Used by Brand to mark a type in a readable way. */
export interface Branding<BrandT> {
_type: BrandT;