Skip to content

Instantly share code, notes, and snippets.

View bogdanq's full-sized avatar
👀
hi!

Bogdan Shelomanov bogdanq

👀
hi!
View GitHub Profile
@bogdanq
bogdanq / ATM.js
Created June 23, 2023 11:10
Задачи собеседований, банкомат, atm
const atm = (sum, limits) => {
const nominals = Object.keys(limits)
.map(Number)
.sort((a, b) => a - b)
const balance = Object.entries(limits).reduce((acc, [key, value]) => acc + key * value, 0)
if (sum > balance) {
return 'Не достатоно денег'
}
@bogdanq
bogdanq / useTableSelect.js
Last active January 31, 2023 21:19
Поддержка мультиселекта и одиночного выбора в таблице с подгрузкой данных из сервера
const getElementsPosition = () => {
console.log("ok")
const dimensions = [320, 480, 640, 960, 1200, 1400, 1600];
const nodes = [...document.querySelectorAll("[data-component-id]")];
const availableWidth = window.innerWidth;
const media = dimensions.find((d) => d >= availableWidth);
@bogdanq
bogdanq / checkRoles.js
Last active July 28, 2020 07:15
Хелперы для гардов
interface IUserContext {
user: User_user;
}
export function onlyAuth(context: IUserContext) {
return Boolean(context.user);
}
export function onlyAdAgent({ user }: IUserContext) {
if (user && user.roles) {
@bogdanq
bogdanq / guard.js
Created July 28, 2020 07:12
Компонент скрытия роутов
const Guard = ({
guards = [],
redirect = "/",
exact = true,
component: Component,
pageTitle,
path,
}) => {
const { checkPermissions } = usePermissions();
const { loading } = useUser();
import React from 'react'
import { Text, View } from 'react-native'
import { createAppContainer } from 'react-navigation'
import { createBottomTabNavigator } from 'react-navigation-tabs'
import { createStackNavigator } from 'react-navigation-stack'
export const App = createAppContainer(
createStackNavigator({
Home: () => (
<View style={styles.container}>
import React from 'react'
import { Text, View } from 'react-native'
import { createAppContainer } from 'react-navigation'
import { createBottomTabNavigator } from 'react-navigation-tabs'
import { createStackNavigator } from 'react-navigation-stack'
const app = createStackNavigator({
Home: () => (
<View style={styles.container}>
<Text style={styles.paragraph}>Home Screen</Text>
import { TransitionGroup, CSSTransition } from "react-transition-group";
export const TransitionComponent = ({
children,
isAnimated,
classNames,
timeout
}) => (
<TransitionGroup>
<CSSTransition
import styled from "styled-components";
const mapPoint = ({ position }) => ({
style: {
top: position.top,
left: position.left
}
});
// api styled позволяет через атрибуты навесить стили
import styled, { css } from "styled-components";
const getStyle = (propsName, styles) => props =>
props[propsName] && styles[props[propsName]];
const is = value => Boolean(value)
const ifProps = (name, styles) => props => is(props[name]) && styles
const buttonStyle = {
mini: css`
import React from 'react'
import { css } from 'styled-components'
export const WithTag = ({ as = 'div', children, to, onClick, ...props }) =>
React.createElement(as, { to, onClick, ...props }, children)
const prop = value => (is(value) ? value : 'initial')
export const mixins = props => css`
align-content: ${prop(props.alignContent)};