Skip to content

Instantly share code, notes, and snippets.

View sagarpanchal's full-sized avatar

Sagar Panchal sagarpanchal

View GitHub Profile
@sagarpanchal
sagarpanchal / home_end.json
Last active March 2, 2026 16:02
Karabiner Elements (MacOS)
{
"description": "HOME/END Fixes",
"manipulators": [
{
"from": { "key_code": "home" },
"to": [{ "key_code": "left_arrow", "modifiers": ["command"] }],
"type": "basic"
},
{
"from": { "key_code": "home", "modifiers": { "mandatory": ["shift"] } },
@sagarpanchal
sagarpanchal / chrome-unsafe-mode.sh
Last active March 2, 2026 16:12
Npm Aws code-artifact integration
function chrome-unsafe-mode {
local os
os="$(uname -s)"
case "$os" in
Darwin*) open -n -a "Google Chrome" --args --user-data-dir="$HOME/chrome-unsafe-mode" --disable-web-security ;;
Linux*) google-chrome --user-data-dir="$HOME/chrome-unsafe-mode" --disable-web-security ;;
esac
}
@sagarpanchal
sagarpanchal / setup-husky.sh
Last active March 2, 2026 16:10
Git hooks auto-setup shell script
#!/bin/zsh
# This script automates the process of setting up Husky for an npm package in a git repo.
# It creates the .husky directory, installs Husky, and sets up the pre-commit and post-merge hooks.
# It also updates the package.json with lint-staged configuration.
# Usage: ./setup-husky.sh
set -e
if [ ! -f "$PWD/package.json" ]; then
@sagarpanchal
sagarpanchal / globalRefs.ts
Created December 18, 2024 06:30
Hooks to manage Global Refs
import React from 'react'
declare global {
interface GlobalListsMap {
default: unknown
}
interface Window {
globalListsMap: {
[K in keyof GlobalListsMap]: GlobalListsMap[K] extends unknown ? unknown[] : GlobalListsMap[K][] // Turn types into arrays
@sagarpanchal
sagarpanchal / frozenSet.ts
Created November 19, 2024 13:01
Freeze Set
const frozenSet = (iterable) => {
const s = new Set(iterable);
s.add = s.delete = s.clear = undefined;
return s;
};
const test = frozenSet([1, 2, 3, 1, 2])
test.add(4)
@sagarpanchal
sagarpanchal / useNumberInput.ts
Created May 28, 2024 11:42
React: useNumberInput
const useNumberInput = (ref: React.RefObject<HTMLInputElement>) => {
const stepUp = React.useCallback(() => {
if (!ref.current) return
ref.current.stepUp()
ref.current.dispatchEvent(new Event("change", { bubbles: true }))
}, [ref])
const stepDown = React.useCallback(() => {
if (!ref.current) return
ref.current.stepDown()
@sagarpanchal
sagarpanchal / LoaderService.ts
Last active February 15, 2024 12:38
Zustand Usage Example
import { createStore } from "zustand"
import { subscribeWithSelector } from "zustand/middleware"
export function chain<T>(object: T) {
const call =
<V>(previousResult: V) =>
<U>(callback: (object: T, result: V) => U) => {
const result = callback(object, previousResult)
return { call: call(result), result: () => result, object: () => object }

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@sagarpanchal
sagarpanchal / tree
Last active January 2, 2024 08:23
TreeNode
# Tree
Tree implementations in different programming languages.
@sagarpanchal
sagarpanchal / grahviz.html
Last active October 27, 2023 13:48
GraphViz
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="author" content="Sagar Panchal | sagar.panchal@outlook.com" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Graph</title>
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml," />
<script src="https://unpkg.com/@hpcc-js/wasm@2/dist/graphviz.umd.js" type="javascript/worker"></script>