Skip to content

Instantly share code, notes, and snippets.

View yashsway's full-sized avatar

Yash Kadaru yashsway

View GitHub Profile
@yashsway
yashsway / rename-js-and-jsx-to-tsx.sh
Created April 1, 2023 12:42
Rename JS and JSX files to TSX (as part of a Typescript migration)
# rename all js to tsx
find . -type f \( -iname '*.js' -or -iname '*.jsx' \) -not -wholename '*node_modules*' -exec sh -c 'mv "$1" "${1%.js*}.tsx"' _ {} \;
# keep js files as ts
find . -type f \( -iname '*.js' -or -iname '*.jsx' \) -not -wholename '*node_modules*' -exec sh -c 'mv "$1" `sed -Ee "s/\.js(x)?$/\.ts\1/g" <<< "$1"`' _ {} \;
# credits to https://github.com/markogresak
@yashsway
yashsway / clamp.js
Last active February 15, 2023 02:10
Clamping a value between a given min and max i.e. never more than the max and never less than min
const clamp = (val, min = 0, max = 1) => {
// if provided min is somehow greater than max, exchange the values
if (min > max) {
[min, max] = [max, min];
}
// get the maximum of two minimized values
return Math.max(min, Math.min(max, val));
}
@yashsway
yashsway / range.js
Created February 10, 2023 16:19
Creates an empty array of set length and fills it with a sequence of numbers, with a customizable step
const range = (start, end, step = 1) => {
let output = [];
if (typeof end === 'undefined') {
end = start;
start = 0;
}
for (let i = start; i < end; i += step) {
output.push(i);
@yashsway
yashsway / LabelBook.cs
Created February 28, 2020 18:29
C# Basic Label Class ready for Localization
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Globalization;
namespace BrainstationShared.Helpers {
public class LabelBook {
public Dictionary<string, LanguageBook> Book { get; set; }
public string SetLang { get; set; } = "en";
public const string NoLabelPlaceholder = "NOT_SET";