Skip to content

Instantly share code, notes, and snippets.

@HugeLetters
HugeLetters / example.ts
Created April 8, 2024 14:59
Drizzle ORM SQLite Trigger migrations
// has to be exported - triggers should be stored in the same folder as table schemas
export const insertTrigger = new Trigger({
name: "update_product_meta_on_new_review",
type: "INSERT",
on: review,
when: ({ newRow }) => eq(newRow.isPrivate, false),
do: ({ newRow }) =>
db
.insert(productMeta)
.values({
@HugeLetters
HugeLetters / settings.json
Created November 25, 2023 10:26
settings
{
"liveServer.settings.donotShowInfoMsg": true,
"explorer.confirmDelete": false,
"sass.format.convert": false,
"sass.disableUnitCompletion": false,
"git.autofetch": true,
"git.confirmSync": false,
"git.suggestSmartCommit": false,
"python.analysis.autoImportCompletions": true,
"python.analysis.completeFunctionParens": true,
{"name":"default","settings":"{\"settings\":\"{\\r\\n \\\"liveServer.settings.donotShowInfoMsg\\\": true,\\r\\n \\\"explorer.confirmDelete\\\": false,\\r\\n \\\"sass.format.convert\\\": false,\\r\\n \\\"sass.disableUnitCompletion\\\": false,\\r\\n \\\"git.autofetch\\\": true,\\r\\n \\\"git.confirmSync\\\": false,\\r\\n \\\"git.suggestSmartCommit\\\": false,\\r\\n \\\"python.analysis.autoImportCompletions\\\": true,\\r\\n \\\"python.analysis.completeFunctionParens\\\": true,\\r\\n \\\"python.analysis.diagnosticMode\\\": \\\"workspace\\\",\\r\\n \\\"python.analysis.inlayHints.functionReturnTypes\\\": true,\\r\\n \\\"javascript.updateImportsOnFileMove.enabled\\\": \\\"always\\\",\\r\\n \\\"editor.unicodeHighlight.allowedLocales\\\": {\\r\\n \\\"ru\\\": true\\r\\n },\\r\\n \\\"editor.accessibilitySupport\\\": \\\"off\\\",\\r\\n \\\"emojisense.languages\\\": {\\r\\n \\\"javascript\\\": true,\\r\\n \\\"javascriptreact\\\": true,\\r\\n \\\"typescript\\\": true,\\r\\n \\\"typescriptreac
{"name":"Svelte","settings":"{\"settings\":\"{\\r\\n \\\"liveServer.settings.donotShowInfoMsg\\\": true,\\r\\n \\\"explorer.confirmDelete\\\": false,\\r\\n \\\"sass.format.convert\\\": false,\\r\\n \\\"sass.disableUnitCompletion\\\": false,\\r\\n \\\"git.autofetch\\\": true,\\r\\n \\\"git.confirmSync\\\": false,\\r\\n \\\"git.suggestSmartCommit\\\": false,\\r\\n \\\"python.analysis.autoImportCompletions\\\": true,\\r\\n \\\"python.analysis.completeFunctionParens\\\": true,\\r\\n \\\"python.analysis.diagnosticMode\\\": \\\"workspace\\\",\\r\\n \\\"python.analysis.inlayHints.functionReturnTypes\\\": true,\\r\\n \\\"javascript.updateImportsOnFileMove.enabled\\\": \\\"always\\\",\\r\\n \\\"editor.unicodeHighlight.allowedLocales\\\": {\\r\\n \\\"ru\\\": true\\r\\n },\\r\\n \\\"editor.accessibilitySupport\\\": \\\"off\\\",\\r\\n \\\"emojisense.languages\\\": {\\r\\n \\\"javascript\\\": true,\\r\\n \\\"javascriptreact\\\": true,\\r\\n \\\"typescript\\\": true,\\r\\n \\\"typescriptreact
@HugeLetters
HugeLetters / api.ts
Last active October 20, 2023 13:23
Openapi-fetch + tanstack-query
import { browser } from '$app/environment';
import { PUBLIC_EXTERNAL_URL, PUBLIC_INTERNAL_URL, PUBLIC_IS_DOCKER } from '$env/static/public';
import type { paths } from '$lib/openapi'; // generated from openapi-typescript
import type { StrictOmit, StrictPick } from '$lib/utils/types'; // these are just Omit|Pick but with autocomplete
import createClient, { type FetchOptions } from 'openapi-fetch';
const baseUrl = browser ? undefined : PUBLIC_IS_DOCKER ? PUBLIC_INTERNAL_URL : PUBLIC_EXTERNAL_URL;
export const api = createClient<paths>({ baseUrl });
type Api = typeof api;
@HugeLetters
HugeLetters / router-gen.ts
Last active September 6, 2024 01:46
SvelteKIt type-safe router
import { watch } from 'chokidar';
import { writeFile } from 'fs/promises';
import { glob } from 'glob';
import { format } from 'prettier';
const pageGlobMatcher = './src/routes/**/+page?(@)*.svelte';
export default async function generateRoutes() {
const paths = await getPaths();
const routes = paths.map(parsePath);
@HugeLetters
HugeLetters / this is bad.tsx
Created September 12, 2023 09:47
How to compose CSS in web frameworks
function Page() {
return (
<div className="flex">
<div>Page</div>
<Component />
</div>
);
}
function Component() {
@HugeLetters
HugeLetters / Header.tsx
Last active September 12, 2023 05:02
Dynamic Delcarative Header
import { contentStackAtom } from "@/hooks/useHeader";
import { useAtomValue } from "jotai";
export default function Header() {
const stack = useAtomValue(contentStackAtom).filter((node) => !!node.content);
return (
<header>
{stack.at(-1)?.content ?? "App Title"}
</header>