Skip to content

Instantly share code, notes, and snippets.

View navin-moorthy's full-sized avatar
💻
Focused

Navin Moorthy navin-moorthy

💻
Focused
View GitHub Profile
@navin-moorthy
navin-moorthy / cn.ts
Last active August 30, 2023 15:10
React Utils
import { twMerge, type ClassNameValue } from "tailwind-merge";
export function cn(...inputs: ClassNameValue[]) {
return twMerge(inputs);
}
@navin-moorthy
navin-moorthy / downloadAllImages.js
Last active July 6, 2023 07:13
Site Boost Utils
// https://www.smashingmagazine.com/2023/06/popular-devtools-tips/#5-download-all-images-on-the-page
$$("img").forEach(async (img) => {
try {
const src = img.src;
// Fetch the image as a blob.
const fetchResponse = await fetch(src);
const blob = await fetchResponse.blob();
const mimeType = blob.type;
// Figure out a name for it from the src and the mime-type.
@navin-moorthy
navin-moorthy / KeysOfValue.ts
Last active June 27, 2023 07:12
Typescript Utils
export type KeysOfValue<T, TCondition = string> = {
[K in keyof T]: T[K] extends TCondition ? K : never;
}[keyof T];
import { getErrorMessage } from "./getErrorMessage.js";
/**
* Adds additional error message to the existing error message.
* @param {unknown} error - The error object.
* @param {string} errorMessage - The additional error message to be added.
* @returns {string} - The updated error message.
*/
export function addAdditionalErrorMessage(
error: unknown,
import { isNonNullable } from "isNonNullable";
export type GetFinalLogoSizeProps = { width: number; height: number; maxHeight: number; maxWidth: number };
export const getFinalLogoSize = ({ width, height, maxHeight, maxWidth }: GetFinalLogoSizeProps) => {
if (isNonNullable(maxHeight) && !isNonNullable(maxWidth)) {
return {
width: Math.floor(width * (maxHeight / height)),
height: maxHeight,
};
# https://markoskon.com/creating-font-subsets/#minimal-english-subset
pyftsubset\
Inter.var.woff2 \
--output-file="Inter.var-english.woff2" \
--flavor=woff2 \
--layout-features="kern,liga,clig,calt,ccmp,locl,mark,mkmk,\
onum,pnum,smcp,c2sc,frac,lnum,tnum,subs,sups,\
cswh,dlig,ss01,ss03,zero"\
--unicodes="U+0000-00A0,U+00A2-00A9,U+00AC-00AE,U+00B0-00B7,\
U+00B9-00BA,U+00BC-00BE,U+00D7,U+00F7,U+2000-206F,U+2074,U+20AC,\
@navin-moorthy
navin-moorthy / asyncWrapper.ts
Last active November 28, 2023 12:03
Node Utils
import { type NextFunction, type Request, type Response } from "express";
export type AsyncHandler = (
request: Request,
response: Response,
next: NextFunction,
) => Promise<void>;
/**
* Wraps an asynchronous route handler function with error handling middleware.
echo "words" | sed '/^words/,$!d'
sed '/^words/,$!d' input.txt > output.txt
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"orta.vscode-jest",
"tlent.jest-snapshot-language-support",
"vespa-dev-works.jestrunit",
"vivaxy.vscode-conventional-commits",
"bradlc.vscode-tailwindcss",
"aaron-bond.better-comments",
@navin-moorthy
navin-moorthy / settings.json
Created June 10, 2022 14:35
Tailwind Intellisense for twrnc
{
// Add the below code to vscode user settings.json
"tailwindCSS.experimental.classRegex": [
["tailwind.style\\(([^)]*)\\)", "\"([^\"]*)\""],
["tailwind.getColor\\(([^)]*)\\)", "\"([^\"]*)\""],
],
"tailwindCSS.experimental.configFile": "your/path/to/tailwind.config.js",
}