Skip to content

Instantly share code, notes, and snippets.

View EdMSL's full-sized avatar

Eduard Trait EdMSL

  • Russia, Novosibirsk
View GitHub Profile
@EdMSL
EdMSL / copy_git_diff.sh
Last active January 30, 2025 09:10 — forked from gwagroves/copy_git_diff.sh
Copy git modified files to another directory
cp -pv --parents `git diff --name-only master..develop -- source/directory` target/directory
cp -pv --parents $(git hist --since="6am" | awk '{print $2}' | xargs | git diff --name-only HEAD $(awk {'print $NF'}) ./) ./ChangedFiles
@EdMSL
EdMSL / CustomStartsWith.cs
Created May 21, 2024 08:48
Замена для неэффективного метода сравнения строк String.StartsWith.
public static bool CustomStartsWith(this string a, string b)
{
int aLen = a.Length;
int bLen = b.Length;
int ap = 0; int bp = 0;
while (ap < aLen && bp < bLen && a [ap] == b [bp])
{
ap++;
@EdMSL
EdMSL / CustomEndsWith.cs
Created May 21, 2024 08:47
Замена для неэффективного метода сравнения строк String.EndsWith.
public static bool CustomEndsWith(this string a, string b)
{
int ap = a.Length - 1;
int bp = b.Length - 1;
while (ap >= 0 && bp >= 0 && a [ap] == b [bp])
{
ap--;
bp--;
}
@EdMSL
EdMSL / capitalize.js
Created September 22, 2022 05:29
Сделать первую букву слова заглавной для одного слова или для всех в строке
const capitalizeFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1)
const capitalizeAll = (str, toLower = false) => (toLower ? str.toLowerCase() : str).replace(/(?:^|\s|["'([{])+\S/g, match => match.toUpperCase())
@EdMSL
EdMSL / generateRandomString.js
Last active July 21, 2023 03:08
Сгенерировать случайную строку (например, для id)
const randomStr = Math.random().toString(36).slice(2);
const anotherRandomStr = length => [...Array(length)].map(() => Math.random().toString(36)[2]).join('');
@EdMSL
EdMSL / MultyTo1DArr.js
Created September 4, 2022 08:28
Перевести многоуровневый массив в одноуровневый
const arr = [1,[2,[3,[4,[5]]]]];
const dArray = arr.toString().split(',').map((num) => Number(num));
@EdMSL
EdMSL / getRandomColor.js
Last active August 16, 2022 03:54
Функции генерации HEX и RGB цветов
const generateRandomHexColor = () =>
`#${Math.floor(Math.random() * 0xffffff).toString(16)}`;
const generateRandomRgbColor = () =>
`rgb(${new Array(3).fill(0).map(() => Math.floor(Math.random() * 256))})`;
@EdMSL
EdMSL / shuffleArray.js
Created August 16, 2022 02:50
Перемешать массив в случайном порядке
const shuffleArray = (arr) => arr.sort(() => Math.random() - 0.5);
@EdMSL
EdMSL / lost.js
Last active July 22, 2022 09:41
Потеря окружения JS и способы решения
// Проблема: Потеря окружения
for(var i = 0; i <= 10; i++) {
setTimeout(function() {
console.log(i)
}, 2000);
}
// 1. С помощью внешней функции через параметр
function func(value) {console.log(value)}
@EdMSL
EdMSL / Days and months
Created March 1, 2020 07:37
Дни недели и месяца
const DAYS = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
];