Skip to content

Instantly share code, notes, and snippets.

@sidisinsane
sidisinsane / extensions.json
Created March 5, 2024 15:40
VSCode Configuration for Python Poetry Projects
{
"recommendations": [
"charliermarsh.ruff"
]
}
@sidisinsane
sidisinsane / stop-other-media.js
Created August 9, 2023 17:51
Stops other media elements from playing when a media element starts playing.
/**
* Stops other media elements from playing when a media element starts playing.
*
* @param {HTMLMediaElement[]} mediaElems - An array of HTML media elements.
*
* @example
*
* // Stop other media elements when one starts playing
* const allMediaElems = document.querySelectorAll("audio, video");
* stopOtherMedia(allMediaElems);
@sidisinsane
sidisinsane / extensions.json
Created July 16, 2023 16:59
Vscode configuration for Python.
{
"recommendations": [
"ms-python.python",
"ms-python.pylint",
"ms-python.black-formatter",
"ms-python.isort"
]
}
@sidisinsane
sidisinsane / dict_unique.py
Last active July 16, 2023 16:52
Return a dictionary containing unique values from a given dictionary.
def dict_unique(dict):
"""
Return a dictionary containing unique values from a given dictionary.
Args:
dict (dict): The input dictionary.
Returns:
dict: A new dictionary with unique values.
@sidisinsane
sidisinsane / str_utils.py
Last active July 16, 2023 16:53
String utilities (transliterate, slugify).
import re
import unicodedata
DIACRITICS_MAP = {
"À": "A",
"Ĕ": "E",
"Ļ": "L",
"Ś": "S",
"Ź": "Z",
"ē": "e",
@sidisinsane
sidisinsane / list_unique.py
Last active July 16, 2023 16:54
Return a list containing unique values from a given array.
import numpy as np
def list_unique(arr):
"""
Return a list containing unique values from a given array.
Args:
arr (list or numpy.ndarray): The input list.
Returns:
@sidisinsane
sidisinsane / array_unique.py
Last active July 16, 2023 16:55
Return an array containing unique values from a given array.
import numpy as np
def array_unique(arr):
"""
Return an array containing unique values from a given array.
Args:
arr (list or numpy.ndarray): The input array.
Returns:
@sidisinsane
sidisinsane / i18n-format-display-names.mjs
Last active July 16, 2023 10:24
Formats a display name (currency, language, region, script) with internationalization.
/**
* @typedef {Object} I18nFormatDisplayNamesType - creates a new type named "I18nFormatDisplayNamesType"
* @property {string} code - The currency-, language-, region-/country- or script-code for which to retrieve the display name.
* @property {string} [locale="en-US"] - The locale (keyof typeof Intl.Locale) to use for formatting the display name.
*
* @description
* - Currency code: The first two letters of the ISO 4217 three-letter code are the same as the code for the country name, and,
* where possible, the third letter corresponds to the first letter of the currency name.
* - Language code: Unicode base language code based on BCP47 subtag values marked as Type "language".
* - Region code: Unicode region code based on BCP47 subtag values marked as Type "region".
@sidisinsane
sidisinsane / i18n-format-dates.mjs
Created June 18, 2023 13:16
Formats a date with internationalization.
/**
* @typedef {Object} I18nFormatDateType - creates a new type named "I18nFormatDateType"
* @property {string} [dateString] - The string representation of the date to be formatted. Defaults to current date.
* @property {string} [locale="en-US"] - The locale (keyof typeof Intl.Locale) to use for formatting the date.
* @property {Intl.DateTimeFormatOptions} [formatOptions] - The options for formatting the date.
*/
/**
* Formats a date with internationalization.
*
@sidisinsane
sidisinsane / format-phone-number.mjs
Last active July 17, 2023 12:53
Formats a phone number using the libphonenumber-js library.
import parsePhoneNumber from "libphonenumber-js";
/**
* @typedef {Object} FormatPhoneNumberType - creates a new type named "FormatPhoneNumberType"
* @property {string} number - The phone number to format.
* @property {"NATIONAL" | "INTERNATIONAL" | "RFC3966"} [property="INTERNATIONAL"] - The desired formatting property.
*/
/**
* Formats a phone number using the libphonenumber-js library.