Skip to content

Instantly share code, notes, and snippets.

@julius1986
julius1986 / quickSort.js
Created January 8, 2025 20:19
Quick sort
let quickSort = (arr) => {
let low = 0;
let high = arr.length;
if (high < 2) return arr;
let pivotIndex = Math.trunc(high / 2);
let pivot = arr[pivotIndex];
let lessArr = [];
let highArr = [];
for (let i = 0; i < high; i++) {
if (i === pivotIndex) {
@julius1986
julius1986 / getRandomNumber.js
Created July 17, 2024 20:08
Functnion to get random number
const getRandomNumber = (from, to) => {
const randomNumber = Math.random();
const readyRandomNumber = Math.floor(randomNumber * to) + from;
return readyRandomNumber;
};
@julius1986
julius1986 / js-httpRequest.js
Created August 10, 2022 14:04
js-httpRequest
export default function httpRequest(method, url, body = undefined, accessToken = localStorage?.getItem("accessToken")) {
const controller = new AbortController();
const signal = controller.signal;
const request = fetch(SERVER_PATH + url, {
method: method,
mode: "cors",
headers: {
"Content-Type": "application/json",
authorization: `Bearer ${accessToken}`
@julius1986
julius1986 / css-sass.scss
Last active April 9, 2020 17:12
css-sass
//создание переменных происходит при помощи $
$mainColor: red;
$secondColor: blue;
.container{
background-color: $mainColor;
color: $secondColor;
.btn{
color: $mainColor;
. - любой символ
[] - тут можно указывать любые символы, а так же диапазоны через - пример [1-8]
$ - конец строки
^ - начало строки
\n - перенос строки
\ - экранирование
\d - любая цифра
\D - любой символ кроме цифры
\s - пробелы
\S - все символы кроме пробела
@julius1986
julius1986 / js-array-methods.js
Last active October 14, 2019 17:41
js-array-methods
const items = [
{name: 'Bike', price: 100},
{name: 'Tv', price: 200},
{name: 'Aalbum', price: 10},
{name: 'Book', price: 5},
{name: 'Phone', price: 1000},
{name: 'Keyboard', price: 25},
]
//возвращает новый массив из отфильтрованных жлементов
@julius1986
julius1986 / css-grid.css
Last active April 14, 2020 18:22
all properties for grid css.
/*Для контейнера*/
display:grid; // делаем наш элемент гридом.
/*ВСЕ РАВНО ДЛЯ АДАПТИВНОГО ДИЗАЙНА ПРИДЕТЬСЯ ИСПЛЬЗОВАТЬ @media*/
/*Либо используем статические значения размеров колонок, либо auto-fit/auto-fill вместе с minmax где
задаем статические размеры. Количество div должно/желательно совпадать с количеством колонок*ряды.
Либо мы должны вручную прописать что какието div будут занимать больше места.*/
/*
указываем число колонок. можем использовать дополнительные функции такие как repeat, minmax.
repeat - позволяет задать количество колонок и применяемые к ним свойства auto-fit/auto-fill
auto-fit/auto-fill - браузер сам задает ширину и если нужно переносит колонки на новую строку.
@julius1986
julius1986 / webpack.conf.js
Last active October 8, 2019 15:18
webpack configuration
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
'index': path.join(__dirname,'/src/index.js'),
'example1': path.join(__dirname,'/src/example1.js'),
},
output: {
filename: '[name].js',
@julius1986
julius1986 / js-fetch.js
Last active July 19, 2019 19:28
js-fetch
function getData(){
return fetch("http://jsonplaceholder.typicode.com/posts", {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, cors, *same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded',
},
@julius1986
julius1986 / react-redux.js
Last active March 18, 2019 15:04
react-redux
/*actoins тут мы создаем действия для нашего редьюсера*/
function nameOfAction(){
return {type:"NAME_OF_ACTION", payload:{name:"some object"} }
}
function addNewUser(){
return {type:"ADD_NEW_USER", payload:{id:11, name:"Zak"} }
}
function increment(){
return {type:"INCREMENT"}
}