Skip to content

Instantly share code, notes, and snippets.

View Abhinav1217's full-sized avatar

Abhinav Kulshreshtha Abhinav1217

View GitHub Profile
@Abhinav1217
Abhinav1217 / StringUtil.ts
Created June 2, 2024 20:00
A collection of utility functions for string manipulation.
/**
* StringUtil.ts
*
* A collection of utility functions for string manipulation.
*
* Attribution: Custom implementations inspired by common JavaScript practices.
*
* ## Contents:
* - `trimWhitespace(str)`: Removes leading and trailing whitespace from a string.
* - `toCamelCase(str)`: Converts a string to camelCase.
@Abhinav1217
Abhinav1217 / CryptoUtil.ts
Created June 2, 2024 19:54
A collection of utility functions for cryptographic operations using Node.js's built-in crypto module.
/**
* CryptoUtil.ts
*
* A collection of utility functions for cryptographic operations using Node.js's built-in crypto module.
*
* Attribution: Utilizes Node.js's native crypto module for cryptographic operations.
*
* ## Contents:
* - `sha256(message)`: Creates a SHA-256 hash of the input message.
@Abhinav1217
Abhinav1217 / RandomUtil.ts
Created June 2, 2024 19:35
A collection of utility functions for generating random data.
/**
* RandomUtil.ts
*
* A collection of utility functions for generating random data.
*
* Attribution: This file was inspired by various online resources and personal coding experience.
*
* ## Contents:
* - `getRandomInt(min, max)`: Generates a random integer within a specified range.
* - `getRandomFloat(min, max)`: Generates a random floating-point number within a specified range.
@Abhinav1217
Abhinav1217 / XlsxUtils.ts
Last active June 2, 2024 19:16
Simple TS/JS utility for xlsx
/**
* XLSX Utilities | Abhinav Kulshreshtha | Unlicense
*
* A collection of utility functions for working with XLSX files in Node.js. These utilities facilitate common tasks such as converting row/column indices to cell addresses, extracting headers from sheets, and converting arrays of objects into worksheets. Feel free to use, modify, and distribute under the Unlicense.
*
* ## Contents:
* - `rowIndexColToCellAddress`: Converts row and column indices to an Excel cell address in A1 notation.
* - `cellAddressToIndices`: Convert Excel cell address (A1 Notation) to row and column indices
* - `getHeaders`: Extracts headers from the first row of an Excel sheet.
* - `objectsToArrayWorksheet`: Converts an array of objects into a worksheet.
@Abhinav1217
Abhinav1217 / FileUtils.ts
Last active June 2, 2024 19:04
Simple TS/JS utility for file IO
/**
* FileUtils Collection | Abhinav Kulshreshtha | Unlicense
*
* A collection of utility functions for file operations, including reading, writing, and checking file existence.
* These functions are designed to simplify common tasks in Node.js applications. Feel free to use, modify, and distribute
* under the Unlicense.
*
* ## Contents:
* - `fileExists`: Checks if a file exists and creates the directory if it doesn't.
* - `readJsonFromFile`: Reads JSON data from a file and returns it as a string.
@Abhinav1217
Abhinav1217 / jest-to-vitest.sh
Created May 25, 2024 10:14 — forked from wojtekmaj/jest-to-vitest.sh
Automatically migrate Jest project to Vitest
#!/bin/bash
# Ensure we're working on the latest version of the main branch
git switch main
git fetch
git pull
# Create a new branch
git switch -c vitest
@Abhinav1217
Abhinav1217 / Microsoft.Powershell_profile.ps1
Last active July 6, 2024 03:59
a basic $PROFILE for powershell
#
# @author Abhinav Kulshreshtha
# @license The Unlicensed
#
# If you get the error: "Running scripts is disabled on this system" when loading the Profile:
# From a PowerShell window opened As Administrator:
# > Set-ExecutionPolicy RemoteSigned
# Select "Y"1
# https://tecadmin.net/powershell-running-scripts-is-disabled-system/
@Abhinav1217
Abhinav1217 / shell-tricks.sh.md
Created March 16, 2023 09:09
Some linux shell tricks

Remove audio tracks from video file.

function ffsilent { ffmpeg -i "$1" -c copy -an "${1%.*}-nosound.${1#*.}" }
@Abhinav1217
Abhinav1217 / useful-git-snippets.md
Last active February 23, 2023 04:19
Some useful git snippets for lesser used tasks

Taken from https://gist.github.com/lttlrck/9628955
Rename a branch both locally and on server.

git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote


git log --oneline -10 # Managable git log.

@Abhinav1217
Abhinav1217 / decorater-example.ts
Created February 6, 2023 15:24
General purpose "decorater" template for Typescript 5
/** Taken from Andrew Burgess YT video */
// https://www.youtube.com/watch?v=_1mQ_A7fq-g
function logged<
This,
Args extends any[],
Return,
Fn extends (this: This, ...args:Args) => Returns>
(
target: Fn,