Git CLI handy commands Prune branches:
git branch | grep -v "master" | xargs git branch -DSwitch to new origin branch:
git fetch origin
git switch | # ~/.bashrc | |
| # Aliases | |
| alias login='eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_gitlab && ssh-add ~/.ssh/id_github' | |
| alias login-github='eval "$(ssh-agent -s)" && git config user.email "email@email.com" && git config core.sshCommand "ssh -i ~/.ssh/id_github" && ssh-add ~/.ssh/id_github' | |
| alias login-gitlab='eval "$(ssh-agent -s)" && git config user.email "email@email.com" && git config core.sshCommand "ssh -i ~/.ssh/id_gitlab" && ssh-add ~/.ssh/id_gitlab' |
Why use worktrees?
Worktrees are particularly useful if you making changes to a repo that will affect untracked files e.g. a dependency change that alters node_modules.
| Worktrees | Branches |
|---|---|
| Independent untracked files | Shared untracked files |
| Have multiple worktrees side by side | Must stash and switch or use git/web UI to compare |
| export default function useLocalStorage(key, initialValue) { | |
| const [value, setValue] = useState(() => { | |
| const jsonValue = localStorage.getItem(key); | |
| if (jsonValue != null) return JSON.parse(jsonValue) | |
| return initialValue; | |
| }) | |
| useEffect(() => { | |
| localStorage.setItem(key, JSON.stringify(value)); | |
| }, [key, value]) |
| interface Pojo { | |
| [key: string]: string | number | undefined; | |
| } | |
| export function stringifyPojo(object: Pojo) { | |
| return JSON.stringify(object); | |
| } | |
| export function saveObject(object: Pojo, key: string) { | |
| try { | |
| const serializedObject = stringifyPojo(object); |
| import { useSearchParams } from 'next/navigation'; | |
| export function getParam(param: string) { | |
| if (!window) return undefined; | |
| const searchString = window.location.search; | |
| const searchParams = new URLSearchParams(searchString); | |
| return decodeURIComponent(`${searchParams?.get(param)}`); | |
| } | |
| export function setParam(param: string, value: string) { |
| 'use client'; | |
| import { useEffect, useRef } from 'react'; | |
| export default function Page() { | |
| const workerRef = useRef<Worker | null>(null); | |
| useEffect(() => { | |
| // Only run in browser | |
| const worker = new Worker('/workers/myWorker.js'); | |
| workerRef.current = worker; |
| type Entry<T> = [number, T]; | |
| type PriorityNode<T> = { | |
| priority: number; | |
| value: T; | |
| seq: number; | |
| }; | |
| type PriorityHeap<T> = { | |
| push: (entry: Entry<T>) => void; |
| // Node type | |
| type Node<T> = { | |
| value: T; | |
| prev: Node<T> | null; | |
| next: Node<T> | null; | |
| }; | |
| // List type | |
| type DoublyLinkedList<T> = { | |
| head: Node<T> | null; |
| import { clsx, type ClassValue } from 'clsx'; | |
| import { twMerge } from 'tailwind-merge'; | |
| export function classMerge(...inputs: ClassValue[]) { | |
| return twMerge(clsx(inputs)); | |
| } |