Skip to content

Instantly share code, notes, and snippets.

View web2ls's full-sized avatar
💭
Endeavor

Alex Slobodyansky web2ls

💭
Endeavor
View GitHub Profile
@web2ls
web2ls / settings.json
Created April 9, 2023 16:58
setting.json file content
{
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[xml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
@web2ls
web2ls / .gitignore
Created April 9, 2023 16:56
.gitignore file content
### Node ###
# Logs
logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Optional npm cache directory
.npm
@web2ls
web2ls / generateRandomString.js
Created March 22, 2022 05:26
Generate random string
const randomString = (len) => {
const chars = 'abcdefhijkmnprstwxyz123456789ABCDEFGHJKMNPQRSTWXYZ';
const totalLength = chars.length;
let randomStr = '';
for (let i = 0; i < len; i += 1) {
randomStr += chars.charAt(Math.floor(Math.random() * totalLength));
}
return randomStr;
};
@web2ls
web2ls / getUniqueArray
Created August 13, 2021 09:53
Function to get array with only unique elements
function getUnique(array) {
const u = {};
const a = [];
for (let i = 0, l = array.length; i < l; ++i) {
if (u.hasOwnProperty(array[i])) {
continue;
}
a.push(array[i]);
u[array[i]] = 1;
}
@web2ls
web2ls / isArrayUnique
Last active August 13, 2021 09:51
Function to check if array is unique
function isUnique(array) {
const u = {};
let isUnique = 1;
for (let i = 0, l = array.length; i < l; ++i) {
if (u.hasOwnProperty(array[i])) {
isUnique = 0;
break;
}
u[array[i]] = 1;
}
@web2ls
web2ls / .prettierrc
Last active July 13, 2021 20:39
.prettierrc example
{
"trailingComma": "es5",
"printWidth": 200,
"tabWidth": 2,
"singleQuote": true,
"jsxSingleQuote": true,
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"jsxBracketSameLine": true
}
@web2ls
web2ls / webpack.common.js
Last active November 5, 2020 18:50
Basic Webpack 5 + HMR basic setup (multiple files)
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isProd = process.env.NODE_ENV === 'production';
const isDev = !isProd;
const filename = ext => isProd ? `bundle.[fullhash].${ext}` : `bundle.${ext}`;
@web2ls
web2ls / webpack.config.js
Last active November 5, 2020 18:51
Basic Webpack 5 + HMR config setup (single file)
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isProd = process.env.NODE_ENV === 'production';
const isDev = !isProd;
// Файл "tsconfig.json":
// - устанавливает корневой каталог проекта TypeScript;
// - выполняет настройку параметров компиляции;
// - устанавливает файлы проекта.
// Присутствие файла "tsconfig.json" в папке указывает TypeScript, что это корневая папка проекта.
// Внутри "tsconfig.json" указываются настройки компилятора TypeScript и корневые файлы проекта.
// Программа компилятора "tsc" ищет файл "tsconfig.json" сначала в папке, где она расположена, затем поднимается выше и ищет в родительских папках согласно их вложенности друг в друга.
// Команда "tsc --project C:\path\to\my\project\folder" берет файл "tsconfig.json" из папки, расположенной по данному пути.
// Файл "tsconfig.json" может быть полностью пустым, тогда компилятор скомпилирует все файлы с настройками заданными по умолчанию.
// Опции компилятора, перечисленные в командной строке перезаписывают собой опции, заданные в файле "tsconfig.json".
@web2ls
web2ls / Hot Observable
Created August 18, 2019 14:17
Hot Observable
import * as Rx from "rxjs";
const observable = Rx.Observable.fromEvent(document, 'click');
// subscription 1
observable.subscribe((event) => {
console.log(event.clientX); // x position of click
});
// subscription 2