Skip to content

Instantly share code, notes, and snippets.

🏖
Working remotely

vladanyes

🏖
Working remotely
Block or report user

Report or block vladanyes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@vladanyes
vladanyes / qsort.js
Created May 5, 2019
Quicksort in JavaScript
View qsort.js
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 Jan 29, 2019
Format float numbers.
View number-format.js
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 Dec 19, 2018
Check if the passed date is today or later(moment.js)
View isColorRed.js
function isColorRed(date) {
return moment.unix(date).isBefore(moment().add(1, 'days'), 'day');
}
@vladanyes
vladanyes / day_days.js
Last active Dec 19, 2018
js день дня дней
View day_days.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 Oct 3, 2018
Bit of content script file.
View сontent.jsx
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 Sep 19, 2018
React click outside element.(no ref)
View clickOutside.jsx
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 Sep 19, 2018
React addEventListener
View React.addEventListener.jsx
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 Aug 23, 2018
jest.conf.js
View Jest config
const {defaults} = require('jest-config');
module.exports = {
// ...
moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],
setupFiles: ["./js/all-browsers/urls.js", "./tests/jest.jquery.js"],
rootDir: '../',
// ...
};
///
View 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
Проверка администратора
View Проверка администратора
export function checkCredentials(params) {
if (
params.username.toLowerCase() !== 'admin' ||
params.password !== '12345'
) {
return false
}
return true
}
You can’t perform that action at this time.