Skip to content

Instantly share code, notes, and snippets.

View johnkueh's full-sized avatar
🙏
Feeling grateful

John Kueh johnkueh

🙏
Feeling grateful
View GitHub Profile
@johnkueh
johnkueh / react-query.tsx
Created September 1, 2023 07:43
trpc-style-react-query
interface ExampleComponentProps {
profileId: string;
}
function ExampleComponent({ profileId }: ExampleComponentProps) {
const profileQuery = queries.profileService.getProfile.useQuery({
profile_id: profileId,
});
const recipesQuery = queries.recipeService.findRecipes.useQuery({
recipe_ids: [],
@johnkueh
johnkueh / 01_RichTextEditor.tsx
Last active August 14, 2023 07:38
Lexical editor Tailwind
"use client";
import { cn } from "@/lib/utils";
import { CodeHighlightNode, CodeNode } from "@lexical/code";
import { AutoLinkNode, LinkNode } from "@lexical/link";
import { ListItemNode, ListNode } from "@lexical/list";
import { TRANSFORMERS } from "@lexical/markdown";
import { LexicalComposer } from "@lexical/react/LexicalComposer";
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
@johnkueh
johnkueh / shadcn-datetime-picker.tsx
Last active August 9, 2023 03:14
shadcn-datetime-picker
import { cn } from "@/lib/utils";
import dayjs from "dayjs";
import customParseFormat from "dayjs/plugin/customParseFormat";
import { CalendarIcon } from "lucide-react";
import { useState } from "react";
import { Button } from "./button";
import { Calendar } from "./calendar";
import { Popover, PopoverContent, PopoverTrigger } from "./popover";
import {
Select,
import { useState } from "react";
import z, { ZodSchema } from "zod";
import { destroy, post, put } from "./fetch";
export type ApiResource<I> = {
path: string;
method: "POST" | "PUT" | "DELETE";
inputSchema: I;
outputSchema: ZodSchema;
};
import z, { ZodSchema } from 'zod';
// GET as json and returns typed response
export async function get<T extends ZodSchema>(path: string, schema: T, config?: RequestInit) {
const res = await fetch(path, config);
return handleResponse(res, schema);
}
export async function post<T extends ZodSchema, R extends ZodSchema>(
1. npx create-next-app@latest --typescript
2. Add devDependencies - ngrok, prettier, concurrently, "concurrently \"next dev\" \"npm run ngrok\" --prefix none"
3. https://ui.shadcn.com/docs/installation/next
4. Copy .vscode/settings , `npx prettier . --write`
5. Add `.env`, add them to .gitignore
6. `npx shadcn-ui@latest add button dialog select form dropdown-menu`
@johnkueh
johnkueh / helpers.ts
Last active June 19, 2023 04:22
openai-function-calling
import { ChatOpenAI } from 'langchain/chat_models/openai';
import { HumanChatMessage } from 'langchain/schema';
import { ZodSchema, z } from 'zod';
import zodToJsonSchema from 'zod-to-json-schema';
import { winstonLogger } from '../winston';
const logger = winstonLogger.child({ service: 'AIService' });
const chatOpenAIModel = new ChatOpenAI({
temperature: 0,
@johnkueh
johnkueh / main.dart
Last active November 15, 2022 05:55
milkrun-vendor-collections
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
void main() => runApp(ProviderScope(child: MyApp()));
class MyApp extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final request = getVendorsForCollectionFutureProvider('123');
final asyncResult = ref.watch(request);
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
@johnkueh
johnkueh / SETUP_ALB_NAKED_DOMAIN_REDIRECT
Last active September 26, 2019 06:35
Use AWS Application Load Balancer to redirect naked domain to subdomain and HTTPS
1. Create new EC2 Security group with the following rules:
INBOUND - HTTP / `0.0.0.0/0, ::/0`
INBOUND - HTTPS / `0.0.0.0/0, ::/0`
OUTBOUND - All Traffic
2. Create new application load balancer
- Listeners: HTTP, HTTPS
- Select same availablity zones as your lambda
- Choose ACM certificate that you issued for domain
- Use previously created security group