Skip to content

Instantly share code, notes, and snippets.

View lawrencecchen's full-sized avatar
🐰

Lawrence Chen lawrencecchen

🐰
View GitHub Profile
@lawrencecchen
lawrencecchen / db.ts
Last active April 2, 2023 10:09
Kysely + Prisma + zod-prisma-types
import { Kysely } from "kysely";
import { PlanetScaleDialect } from "kysely-planetscale";
import { type z } from "zod";
import * as Models from "./prisma/generated/zod/modelSchema";
type RemoveSchema<S extends string> = S extends `${infer Prefix}Schema` ? Prefix : S;
export type Database = {
[K in keyof typeof Models as RemoveSchema<K>]: z.infer<(typeof Models)[K]>;
};
@lawrencecchen
lawrencecchen / kyselyAdapter.ts
Last active February 10, 2023 10:04
next-auth kysely adapter
import type { Kysely, RawBuilder } from "kysely";
import type { Account } from "next-auth";
import type {
Adapter,
AdapterSession,
VerificationToken,
AdapterUser,
} from "next-auth/adapters";
import type { DB } from "shared";
@lawrencecchen
lawrencecchen / useSwc.ts
Created September 3, 2022 08:16
react hook wrapper for swc
import { useEffect, useState } from "react";
import * as swc from "@swc/wasm-web";
let __initialized = false;
type SWC = Omit<typeof swc, "default" | "initSync">;
let __swc: SWC;
export default function useSwc() {
const [initialized, setInitialized] = useState(__initialized);
const [_swc, setSwc] = useState<SWC>(__swc);
@lawrencecchen
lawrencecchen / LLink.tsx
Created August 22, 2022 03:11
a next.js link that can be disabled.
@lawrencecchen
lawrencecchen / AutosizeTextarea.tsx
Last active February 27, 2023 02:47
autosize with react
import autosize from "autosize";
import { forwardRef, useEffect, useRef } from "react";
const AutosizeTextarea = forwardRef<
HTMLTextAreaElement,
React.DetailedHTMLProps<
React.TextareaHTMLAttributes<HTMLTextAreaElement>,
HTMLTextAreaElement
> & {
onResize?: (target: HTMLTextAreaElement) => void;
@lawrencecchen
lawrencecchen / useTheme.ts
Created August 16, 2022 00:14
useTheme() for react/tailwind (using usehooks-ts)
// npm i usehooks-ts
import { useEffect } from "react";
import { useDarkMode } from "usehooks-ts";
export function useTheme() {
const theme = useDarkMode();
useEffect(() => {
if (theme.isDarkMode) {
document.body.classList.add("dark");
@lawrencecchen
lawrencecchen / yjs-syncedstore.tsx
Created July 27, 2022 07:50
yjs + syncedstore. by default, syncedstore does not come with a context, so this exists.
import { getYjsValue, syncedStore } from "@syncedstore/core";
import {
DocTypeDescription,
MappedTypeDescription,
} from "@syncedstore/core/types/doc";
import { useSyncedStore } from "@syncedstore/react";
import { createContext, useContext, useEffect, useState } from "react";
import { WebsocketProvider } from "y-websocket";
import * as Y from "yjs";
@lawrencecchen
lawrencecchen / tinysync.ts
Created July 19, 2022 08:26
A Typescript first queue/job/schedule engine.
// i like trpc. i like autocomplete. i like vercel/serverless.
// netlify acquired quirrel.
// theo would shill for a type safe option.
// there's a gap for a type-safe scheduling/cron/queuing/realtime and i want to fill it.
// also, quirrel has weird syntax for
// framing: typescript-first bindings for what you would typically use redis for
const appRouter = createRouter();
@lawrencecchen
lawrencecchen / $.ts
Last active April 11, 2024 04:23
next-auth with remix
// app/routes/api/auth/$.ts
import NextAuth from "~/lib/next-auth/index.server";
export const { action, loader } = NextAuth({
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}),
],
@lawrencecchen
lawrencecchen / vim-cheatsheet.md
Last active June 11, 2021 00:19 — forked from nerdalert/vim-cheatsheet.md
VIM Cheatsheet

VIM Cheatsheet

Cursor movement

h - move cursor left
j - move cursor down
k - move cursor up
l - move cursor right

w - jump forwards to the start of a word