Skip to content

Instantly share code, notes, and snippets.

View bryanprimus's full-sized avatar
🏠
Working from home

Bryan Lumbantobing bryanprimus

🏠
Working from home
View GitHub Profile
@bryanprimus
bryanprimus / .zshrc
Created March 28, 2025 06:17
gclb alias to clean git local branches and keep `development` as the only branch left
unalias gclb 2>/dev/null
gclb() {
git checkout development || return
local branches
branches=$(git branch --format="%(refname:short)" | grep -Fxv "development")
if [ -z "$branches" ]; then
echo $'\033[0;32mNo branches to be deleted.\033[0m'
return
fi
@bryanprimus
bryanprimus / zod-file-validation.tsx
Last active September 14, 2024 15:03
Zod schema to validate input type file
import { z } from "zod"
const schema = z.object({
file:
typeof window === "undefined" // this is required if your app rendered in server side, otherwise just remove the ternary condition
? z.undefined()
: z
.instanceof(FileList)
.refine(file => file.length !== 0, {
message: "File is required",
@nandorojo
nandorojo / use-swr-infinite-enhanced.ts
Last active July 10, 2023 11:01
useSWRInfinite with pagination & typescript safety
import { ConfigInterface, useSWRInfinite } from 'swr'
import { useMemo, useCallback, useRef } from 'react'
import last from 'lodash.last'
import get from 'lodash.get'
type PageKeyMaker<Page, Key extends any[]> = (
index: number,
previousPageData?: Page
/**
* Mutable ref object. Set this to `true` before the request and `false` afterwards if the request is fetching more.