Skip to content

Instantly share code, notes, and snippets.

View konstantin24121's full-sized avatar
🖖
кто к нам с чем зачем, тот от того и того

Konstantin konstantin24121

🖖
кто к нам с чем зачем, тот от того и того
  • Cyprus, Limassol
View GitHub Profile
@konstantin24121
konstantin24121 / verifyTelegramWebAppData.tsx
Last active February 17, 2024 10:58
Telegram Bot 6.0 Validating data received via the Web App node implementation
const TELEGRAM_BOT_TOKEN = '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw'; // https://core.telegram.org/bots#creating-a-new-bot
export const verifyTelegramWebAppData = async (telegramInitData: string): boolean => {
// The data is a query string, which is composed of a series of field-value pairs.
const encoded = decodeURIComponent(telegramInitData);
// HMAC-SHA-256 signature of the bot's token with the constant string WebAppData used as a key.
const secret = crypto
@konstantin24121
konstantin24121 / UserActions.ts
Created July 6, 2019 07:10
Пример с react-stores
export class UserActionsClass {
public async requestProfile(): void {
const result = await api.send('profile', 'user', {});
this.updateProfile();
}
private updateProfile(data) {
// convert data to userStore acceptable view
newProfile = ...
//
@konstantin24121
konstantin24121 / cloudSettings
Created February 25, 2019 16:00
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-02-25T16:00:03.584Z","extensionVersion":"v3.2.5"}
@konstantin24121
konstantin24121 / TagsEditable.jsx
Last active May 1, 2018 08:58
Component example from Relap-UI (Bigger, Longer & Uncut)
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
/* subcomponents */
import A from '../A';
import DropdownFiltered from '../DropdownFiltered';
import InlineSVG from '../InlineSVG';
import Tooltip from '../Tooltip';
@konstantin24121
konstantin24121 / TextField.jsx
Created May 1, 2018 08:56
Old component with pcss and flow
// @flow
import React, { PureComponent } from 'react';
// Helpers
import classNameBind from 'classnames/bind';
import { upperFirst } from 'utils';
import s from './TextField.pcss';
const cn = classNameBind.bind(s);
@konstantin24121
konstantin24121 / UserPanel.jsx
Created May 1, 2018 08:38
Container example
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import * as routes from 'config/routes';
import { ACTIONS as authActions } from 'redux/modules/auth';
import { ACTIONS as sitesActions, TYPES as SITES_TYPES } from 'redux/modules/sites';
import { Dropdown, Menu, Avatar, Select, Tooltip } from 'antd';
@konstantin24121
konstantin24121 / IndentStyled.js
Created May 1, 2018 08:33
Styled Component example
import AppPropTypes from 'common/types/AppPropTypes';
import styled, { css } from 'styled-components';
import { applyIfNotNull } from 'styles/utils';
const sizeMap = ['Zero', 'Xs', 'Sm', 'Md', 'Bg', 'Lg'];
const applySize = (size, inverse, theme) => {
return applyIfNotNull(size, () => (`${inverse ? '-' : ''}${theme[`margin${sizeMap[size]}`]}`));
};
@konstantin24121
konstantin24121 / atLeast.js
Created May 1, 2018 08:25
At least validator with test
/**
* Array must containt at least nessesary values
* @param {Number} [count=1] nessesary values in array
* @param {String} [message='You must select at least one of the options'] error message
* @return {?String}
*/
const atLeast = (
count = 1,
message = 'You must select at least one of the options') =>
(value) => {
@konstantin24121
konstantin24121 / syncMiddleware.js
Created May 1, 2018 08:13
Middleware for syncing actions between tabs
/**
* Middleware for syncing actions between tabs
*/
export default () => (next) => (action) => {
if (action.sync) {
delete action.sync;
localStorage.setItem(`${__PROJECT_NAME__}.storeSync`, JSON.stringify({
action,
_hash: Date.now(),
}));
@konstantin24121
konstantin24121 / actions.js
Created May 1, 2018 08:10
Reducer and async action
import TYPES from './types';
// Fetch hypothesis
export const fetchStart = ({ id, segment }) => ({
type: TYPES.fetching,
payload: {
id,
segment,
},
});