This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
printWidth: 120, // max 120 chars in line, code is easy to read | |
useTabs: false, // use spaces instead of tabs | |
tabWidth: 2, // "visual width" of of the "tab" | |
trailingComma: 'es5', // add trailing commas in objects, arrays, etc. | |
semi: true, // add ; when needed | |
singleQuote: true, // '' for stings instead of "" | |
bracketSpacing: true, // import { some } ... instead of import {some} ... | |
arrowParens: 'always', // braces even for single param in arrow functions (a) => { } | |
jsxSingleQuote: false, // "" for react props, like in html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In main App or Layout component add following: | |
const isMobile = useMediaQuery({ maxWidth: 767 }); // From react-responsive, Material UI or other styling library | |
useEffect(() => { | |
// Due to SSR/SSG we can not set 'app-layout onMobile' or 'app-layout onDesktop' on the server | |
// If we modify className using JS, we will got Warning: Prop `className` did not match. Server: "app-layout" Client: "app-layout onDesktop" | |
// So we have to apply document.body.class using the hook :) | |
if (isMobile) { | |
document.body.classList.remove('onDesktop'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import log from 'loglevel'; | |
log.setLevel(process.env.LOG_LEVEL || process.env.REACT_APP_LOG_LEVEL || log.levels.ERROR); | |
log.info('log.level:', Object.keys(log.levels)[log.getLevel()]); | |
// Internal cache for time() and timeEnd() calls | |
const _timers = {}; | |
/** | |
* Analog of console.time() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
/** | |
* Renders "invisible" div to use as a first element in Material UI Menu, and other popup components who obtain | |
* a DOM ref from the child component. This allows to avoid: "Warning: Function components cannot be given refs. | |
* Attempts to access this ref will fail. Did you mean to use React.forwardRef()" | |
* @class InvisibleRef | |
*/ | |
const InvisibleRef = React.forwardRef((props, ref) => { | |
const styleInvisible = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useMemo } from 'react'; | |
const sortByAbc = ([a], [b]) => a.localeCompare(b); | |
const sortByZxy = ([a], [b]) => b.localeCompare(a); | |
const sortNone = () => 0; | |
/** | |
* Renders <ul> list with all properties of the given JavaScript object | |
* @param {object} object - object to print out | |
* @param {boolean} [sortAbc] - properties sorted A-Z when true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.8" | |
services: | |
# PostgeSQL server is running on localhost:8200 | |
postgres: | |
image: postgres | |
restart: always | |
environment: | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_USER: postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const UNMISTAKABLE_CHARS = "23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz"; | |
const BASE64_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789-_"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem | |
function climbingLeaderboard(scores, alice) { | |
let positionsCount = 1; | |
const uscores = [scores[0]]; // Unique scores only, shorter array | |
scores.reduce((prev, curr) => { | |
if (prev != curr) { | |
positionsCount++; | |
uscores.push(curr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { CircularProgress, LinearProgress } from '@material-ui/core/'; | |
/** | |
* Wraps the React Component with React.Suspense and FallbackComponent while loading. | |
* @param {React.Component} WrappedComponent - lazy loading component to wrap. | |
* @param {React.Component} FallbackComponent - component to show while the WrappedComponent is loading. | |
*/ | |
export const withSuspense = (WrappedComponent, FallbackComponent = null) => { | |
return class extends React.Component { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable import/prefer-default-export */ | |
/* eslint-disable no-param-reassign */ | |
/** | |
* Shuffles array in place. ES6 version. | |
* @param {Array} a - array containing all items to shuffle. | |
*/ | |
export function shuffle(a) { | |
for (let i = a.length - 1; i > 0; i--) { | |
const j = Math.floor(Math.random() * (i + 1)); |
NewerOlder