Skip to content

Instantly share code, notes, and snippets.

View smitroshin's full-sized avatar

Serghei Mitroșin smitroshin

  • Amdaris
  • Chisinau, Moldova
View GitHub Profile
@smitroshin
smitroshin / decomposeIntNr.js
Created December 31, 2021 10:06
Decompose integer number by grade
/**
* Decompose integer number by grade
*
* @param {number} num
* @returns {number[]}
*/
const decomposeIntNr = (num) =>
`${num}`.split('').map((itm, i, arr) => itm * 10 ** (arr.length - i - 1));
console.log(decomposeIntNr(346)); // Output: [300, 40, 6]
@smitroshin
smitroshin / tailwind_utilities.txt
Created March 15, 2022 11:45
Tailwind.css utilities
Absolute center: absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2
@smitroshin
smitroshin / multiple_ssh_setting.md
Created April 1, 2022 10:22 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@smitroshin
smitroshin / rainbow_text.css
Created May 20, 2022 11:44
CSS Rainbow Text
.rainbow-text {
background-image: var(--rainbow-gradient,#fff);
background-size: 100%;
background-repeat: repeat;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
-moz-background-clip: text;
-moz-text-fill-color: transparent;
filter: drop-shadow(0 0 2rem #000);
text-shadow: none;
@smitroshin
smitroshin / makeData.js
Created January 17, 2023 08:52
Generate a list of persons
/**
* Source: https://github.com/TanStack/table/blob/v7/examples/filtering/src/makeData.js
*/
import namor from 'namor'
const range = len => {
const arr = []
for (let i = 0; i < len; i++) {
arr.push(i)
@smitroshin
smitroshin / asyncHelper.js
Last active January 21, 2023 16:06
Async + Await Error Handling Strategy
/**
* Source: https://youtu.be/wsoQ-fgaoyQ
*/
export const asyncHelper = (promise) =>
Promise.allSettled([promise]).then(([{ value, reason }]) => ({
data: value,
error: reason,
}));
@smitroshin
smitroshin / getNumericEnum.ts
Created February 2, 2023 14:24
Get from a numeric `enum` just `keys` or just 'values'
/**
* Get from a numeric `enum` just `keys` or just 'values'
*
* Source: https://www.sharooq.com/how-to-access-keys-and-values-of-an-enum-in-typescript
*
* @param target
* @param NumericEnum
* @returns
*/
export const getNumericEnum = (target: "keys" | "values", NumericEnum: Record<any, any>) =>
@smitroshin
smitroshin / toKebabCase.ts
Created June 26, 2023 14:30
Convert a text to kebab-case format
/**
* Convert a text to kebab-case format
*/
export const toKebabCase = (text: string) =>
text
.trim()
.replace(/([a-z])([A-Z])/g, "$1-$2") // insert dash between lowercase and uppercase letters
.replace(/\s+/g, "-") // replace spaces with dashes
.toLowerCase(); // convert all characters to lowercase
@smitroshin
smitroshin / pxToRem.ts
Created July 12, 2023 15:10
Convert "px" to "rem"
/**
* Assuming 1rem = 16px
*
* 14 => 0.875
*/
export const pxToRem = (val: number, htmlFontSize?: number) => val / (htmlFontSize ?? 16);
/**
* Assuming 1rem = 16px
*
@smitroshin
smitroshin / axiosAsyncHelper.ts
Last active August 30, 2023 08:48
Async + Await Error Handling Strategy using Axios
import { AxiosError, AxiosResponse } from "axios";
/**
* Axios types overload
*/
export function asyncHelper<ResponseType = any, ErrorType = any>(
promise: Promise<AxiosResponse<ResponseType | ErrorType, any>> | null | undefined | false
): Promise<{ response: AxiosResponse<ResponseType> | null; error: AxiosError<ErrorType> | null }>;
/**