Skip to content

Instantly share code, notes, and snippets.

View chy4egg's full-sized avatar
👋
Hi there

Aleksandr Mikhailov chy4egg

👋
Hi there
  • Conzylum
  • Nicosia, Cyprus
View GitHub Profile
@chy4egg
chy4egg / ImageUploader.tsx
Created March 5, 2020 07:40
An example of image uploader and cropper written on react
import React, { useCallback, useState, useRef } from 'react'
import { useDropzone } from 'react-dropzone'
import styles from './ImageUploader.module.scss';
import Cropper from 'react-cropper';
import 'cropperjs/dist/cropper.css';
import axios from 'axios';
import { Button } from 'components/buttons/button/Button';
import { DialogWindow } from 'components/dialogWindow/DialogWindow';
import { optimizeImage } from './helpers/optimizeImage';
@chy4egg
chy4egg / PageOverlay.ts
Created July 1, 2019 12:10
A typescript page-overlay with scroll-blocking feature
// detectPassiveEvents - для избежания ошибок и увеличения производительности в chromium-браузерах
// @ts-ignore
import detectPassiveEvents from 'detect-passive-events'
const passiveEvents = detectPassiveEvents.hasSupport
type TConstructorOptions = {
className?: string,
offsetTop?: number,
color?: string,
@chy4egg
chy4egg / objectToArray.js
Last active December 25, 2018 11:27
Object => Array (js)
export default function (obj, property, keys = false) {
if(!obj) return [];
if(Array.isArray(obj)) return obj;
if(keys) return Object.keys(obj);
return Object.keys(obj).map((key) => {
let item = Object.assign(obj[key]);
if(property) {
@chy4egg
chy4egg / fnDelay.js
Created August 8, 2018 11:48
Function that delays something
export default (function fnDelay(){
var timer = 0;
return function(callback, ms){
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
@chy4egg
chy4egg / example.js
Last active June 21, 2018 10:34
Delivery types comparison example
checkAvailableConfirmTypes() {
// variables
let oldTypes = [
{id: "2",text: "operator's call", show: true},
{id: "4",text: "confirm by sms", show: true}
];
let newTypes = {
0: "2",
};
//add a new Set from newTypes
@chy4egg
chy4egg / removeTagsFromString.js
Created June 13, 2018 10:39
Remove html-tags from any string (es6)
/**
*
* @param string
* @return string
*/
export default function(string) {
const REG = /(<([/\w]+)>)/gi;
if (REG.test(string)) {
string = string.replace(REG, "");
@chy4egg
chy4egg / .eslintrc.json
Created May 15, 2018 09:31
.eslintrc.json
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
@chy4egg
chy4egg / .vimrc
Created April 24, 2018 10:28
My vim config
" auto reload .vimrc when changed, this avoids reopening vim
autocmd! bufwritepost .vimrc source %
set nocompatible " be iMproved, required
filetype on " required
"set universal change-buffer
set clipboard=unnamedplus
@chy4egg
chy4egg / formatData.js
Last active May 10, 2018 09:58
Data formatting methods (js) es6
const formatData = {
// Граммы переводит в килограммы
weight : function (weight) {
weight = parseFloat(weight);
let dimension = '';
if (weight < 1000) {
dimension = ' г';
} else {
dimension = ' кг';
@chy4egg
chy4egg / code.js
Last active April 19, 2018 07:30
StickyBar (js) es6 + babel + jQuery
/**
* ENG
* Makes element fixed only for the mobile version of site (until 768px)
* @constructor
* @param {string} sTarget - target css-class for the element, which becomes fixed (.j-sticky-bar)
* @param {string} sFixedClass - the name of the css-class you want to add to the sTarget element (j-fixed)
* @param {sContent} sFixedClass - when sTarget becomes fixed, sContent element gets additional padding-top (body)
*/
/**