Skip to content

Instantly share code, notes, and snippets.

View vladanyes's full-sized avatar
🏠
Working remotely

Vlad R vladanyes

🏠
Working remotely
  • Remote
View GitHub Profile
@vladanyes
vladanyes / qsort.js
Created May 5, 2019 04:25
Quicksort in JavaScript
const arrayToSort = [1,9,2,8,3,7,4,6,5];
const sort = array => {
if (array.length < 2) return array;
const [pivot, ...restItems] = array;
const less = [...restItems].filter(item => item < pivot);
const greater = [...restItems].filter(item => item > pivot);
console.log('test');
return sort(less).concat(pivot).concat(sort(greater));
};
@vladanyes
vladanyes / number-format.js
Created January 29, 2019 07:02
Format float numbers.
function formatNumber(num) {
return Number(num).toFixed(2).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1 ').replace('.', ',').replace('.00', '');
}
@vladanyes
vladanyes / isColorRed.js
Last active December 19, 2018 12:32
Check if the passed date is today or later(moment.js)
function isColorRed(date) {
return moment.unix(date).isBefore(moment().add(1, 'days'), 'day');
}
@vladanyes
vladanyes / day_days.js
Last active April 13, 2022 21:41
js день дня дней
const lastDigitToWord = (digit) => {
const lastFigure = parseInt(digit.toString().substr(digit.toString().length - 1, 1));
if (digit >= 11 && digit < 15) {
return 'Дней';
}
else {
if (lastFigure == 1) return 'День';
if (lastFigure > 1 && lastFigure < 5) return 'Дня';
if (lastFigure == 0 || lastFigure >= 5) return 'Дней';
}
@vladanyes
vladanyes / сontent.jsx
Last active October 3, 2018 16:14
Bit of content script file.
import _ from "lodash";
import React from "react";
import { connect } from "react-redux";
import Header from "./Header.jsx";
import NavigationBar from "./NavigationBar.jsx";
import TabContainer from "./TabContainer.jsx";
import { getFavIcon, getDomain } from "../../tools/utils.js";
import { INJECT_SLIDER_SELECTORS } from '../../tools/const.js';
import Settings from './Routes/Settings.jsx';
import UpdatePopUp from './Routes/UpdatePopUp.jsx';
@vladanyes
vladanyes / clickOutside.jsx
Created September 19, 2018 06:05
React click outside element.(no ref)
iconClick = () => {
if (this.state.showMenu === 'none') {
this.showMenu();
document.addEventListener('click', this.iconClickOutside);
} else if (this.state.showMenu === 'flex') {
this.hideMenu();
document.removeEventListener('click', this.iconClickOutside);
}
}
iconClickOutside = (e) => {
@vladanyes
vladanyes / React.addEventListener.jsx
Last active September 19, 2018 06:11
React addEventListener
componentDidMount() {
const elem = ReactDOM.findDOMNode(this.elementToFire);
elem.addEventListener('scroll', this.fireOnScroll, true);
}
componentWillUnmount() {
const elem = ReactDOM.findDOMNode(this.elementToFire);
elem.removeEventListener('scroll', this.fireOnScroll, true);
}
@vladanyes
vladanyes / Jest config
Last active August 23, 2018 05:00
jest.conf.js
const {defaults} = require('jest-config');
module.exports = {
// ...
moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],
setupFiles: ["./js/all-browsers/urls.js", "./tests/jest.jquery.js"],
rootDir: '../',
// ...
};
///
@vladanyes
vladanyes / Scroll direction
Created May 20, 2018 07:58
Scroll direction
var lastScrollTop = 0;
$(window).on('scroll', function() {
st = $(this).scrollTop();
if(st < lastScrollTop) {
console.log('up 1');
}
else {
console.log('down 1');
// getImages();
}
@vladanyes
vladanyes / Проверка администратора
Created May 19, 2018 15:50
Проверка администратора
export function checkCredentials(params) {
if (
params.username.toLowerCase() !== 'admin' ||
params.password !== '12345'
) {
return false
}
return true
}