Skip to content

Instantly share code, notes, and snippets.

View aryanprince's full-sized avatar
🪄
Working Magic

Aryan Prince aryanprince

🪄
Working Magic
View GitHub Profile
@aryanprince
aryanprince / mysql-docker-compose.yml
Last active March 1, 2024 23:17
Setting up Postgres and MySQL locally using Docker Compose
version: "3.9"
name: myprojectname-mysql
services:
# This is your local MySQL database instance
mysql-db:
image: mysql
restart: always
environment:
@aryanprince
aryanprince / index.ts
Created February 4, 2024 06:25
Singleton Drizzle client during dev, to prevent errors from Next.js HMR
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import { env } from "~/env.js";
import * as schema from "./schema";
import { type PostgresJsDatabase } from "drizzle-orm/postgres-js";
// Fix for "sorry, too many clients already"
declare global {
@aryanprince
aryanprince / nextjs14-vps-guide.md
Last active May 9, 2024 18:42 — forked from ByteGrad/gist:790455da551e9771d67f8e434cdf54d1
Quickly deploy a Next.js 14 app on a VPS (Droplets, EC2, etc.) with app router, RSCs, and other Next.js features

from aryan: most guides i found online weren't helpful for me, hope this helps tho :)

1. Connect to machine

ssh root@<server-ip-address>

Optional but recommended:

sudo apt update && sudo apt upgrade -y
@aryanprince
aryanprince / insertroutename.ts
Last active November 23, 2023 02:15
How to validate POST request body using `zod` to ensure typesafety (for pages router API endpoints)
const createUserRequestSchema = z.object({
name: z.string(),
email: z.string().email(),
})
type CreateUserRequestBody = z.infer<typeof createUserRequestSchema>
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
@aryanprince
aryanprince / zod-optional-null.ts
Created November 16, 2023 13:15 — forked from ciiqr/zod-optional-null.ts
zod optional/nullable/nullish differences
// zod schema
z.object({
// valid if string or:
optional: z.string().optional(), // field not provided, or explicitly `undefined`
nullable: z.string().nullable(), // field explicitly `null`
nullish: z.string().nullish(), // field not provided, explicitly `null`, or explicitly `undefined`
});
// type
{
@aryanprince
aryanprince / recover-deleted-branch.md
Last active May 12, 2023 02:32 — forked from umayr/recover-deleted-branch.sh
How to recover a deleted branch

Pre-requisite: You have to know your last commit message from your deleted branch.

git reflog

Search for message in the list: a901eda HEAD@{18}: commit: <last commit message>

Now you have two options, either checkout revision or HEAD

@aryanprince
aryanprince / git.md
Created May 12, 2023 02:14
How to replace 'main' branch with 'better_branch'

Make sure everything is pushed up to your remote repository (GitHub):

git checkout main

Overwrite "main" with "better_branch":

git reset --hard better_branch
<p class="bg-gradient-to-r from-purple-400 to-green-600 bg-clip-text text-8xl font-extrabold text-transparent">Text Goes Here</p>

Commit types

Commit Type Title Description Emoji
feat Features A new feature
fix Bug Fixes A bug Fix 🐛
docs Documentation Documentation only changes 📚
style Styles Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) 💎
refactor Code Refactoring
@aryanprince
aryanprince / git-cheatsheets.sh
Last active February 16, 2023 18:28 — forked from lttlrck/gist:9628955
Useful Git commands I use every now and then
# Rename Git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote