Skip to content

Instantly share code, notes, and snippets.

View GLD5000's full-sized avatar

Gareth L Devlin GLD5000

View GitHub Profile
@GLD5000
GLD5000 / Git-Helper.md
Last active March 18, 2026 16:25
Git CLI handy commands

Git Helper

Git CLI handy commands Prune branches:

git branch | grep -v "master" | xargs git branch -D

Switch to new origin branch:

git fetch origin
git switch 
@GLD5000
GLD5000 / .bashrc
Last active January 20, 2026 15:21
SSH Tips and Tricks
# ~/.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'
@GLD5000
GLD5000 / worktrees-cheatsheet.md
Last active May 7, 2026 13:56
Git worktrees cheatsheet

Git worktrees cheatsheet

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
@GLD5000
GLD5000 / useLocalStorage.ts
Created August 6, 2025 07:26
Simple local storage hook
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])
@GLD5000
GLD5000 / sessionStorage.ts
Created August 5, 2025 20:51
Session / Local storage utils
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);
@GLD5000
GLD5000 / hooksSearchParams.ts
Created August 5, 2025 20:48
Search Params Custom hooks
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) {
@GLD5000
GLD5000 / ClientWebworker.tsx
Created August 5, 2025 20:42
Webworker implementation in Next.js
'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;
@GLD5000
GLD5000 / minMaxTupleHeap.ts
Created August 5, 2025 20:35
Min/Max Priority Tuple Heap
type Entry<T> = [number, T];
type PriorityNode<T> = {
priority: number;
value: T;
seq: number;
};
type PriorityHeap<T> = {
push: (entry: Entry<T>) => void;
@GLD5000
GLD5000 / linkedList.ts
Created August 5, 2025 20:00
Linked list implementation
// Node type
type Node<T> = {
value: T;
prev: Node<T> | null;
next: Node<T> | null;
};
// List type
type DoublyLinkedList<T> = {
head: Node<T> | null;
@GLD5000
GLD5000 / classMerge.ts
Created August 5, 2025 19:50
Class merging pattern for Tailwind
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function classMerge(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}