Skip to content

Instantly share code, notes, and snippets.

View alersenkevich's full-sized avatar
🤔
hard working

01001010011011110100101001101111 alersenkevich

🤔
hard working
  • Yekaterinburg, Russian Federation
View GitHub Profile
@alersenkevich
alersenkevich / accordion-react-component-with-animation.markdown
Created July 19, 2019 10:55
Accordion react component with animation
@alersenkevich
alersenkevich / .eslintrc
Created July 19, 2019 06:50
eslint + typescript + react
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": { "jsx": true },
"ecmaVersion": 2018,
"sourceType": "module"
},
"extends": [
"airbnb",
"prettier",
@alersenkevich
alersenkevich / reduce.go
Created July 13, 2019 20:02
reduce in go
func Reduce(arr, reduceFunc, acc interface{}) float64 {
arrValue := redirectValue(reflect.ValueOf(arr))
if !IsIteratee(arrValue.Interface()) {
panic("First parameter must be an iteratee")
}
returnType := reflect.TypeOf(Reduce).Out(0)
isFunc := IsFunction(reduceFunc, 2, 1)
@alersenkevich
alersenkevich / .js
Created March 19, 2019 13:14
react + typescript + webpack
const path = require('path');
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
entry: "./src/index.tsx",
output: {
path: path.resolve(__dirname, '../public'),
filename: "bundle.js",
@alersenkevich
alersenkevich / .js
Created December 11, 2018 07:54
webpack.config.js
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, '../public'),
filename: 'bundle.js',
},
devtool: 'source-map',
@alersenkevich
alersenkevich / .ts
Last active September 26, 2018 11:27
parsing
const nominals = ['BTC', 'ETH', 'USD'];
const timeIntervals = ['1m', '5m', '15m', '1h', '4h', '1d'];
const loadingResult = await Promise.all(nominals.map(
(nominal, nominalKey) => Promise.all(timeIntervals.map(
(interval, intervalKey) => models[`Price${interval + nominal}`]
.bulkCreate(comparedSplittedPrices[nominalKey][intervalKey]),
)),
));
@alersenkevich
alersenkevich / .ts
Last active March 11, 2018 04:55
promise timing wrapper
const timingWrapper = <T>(fn: Function, ms: number): Promise<T> => new Promise(
resolve => setTimeout(
async () => resolve(await fn()),
ms,
),
);
@alersenkevich
alersenkevich / compose.js
Created December 12, 2017 19:29
compose FP
const compose = (...args) => (...currentArgs) => {
let result = args[0](...currentArgs)
for (let i = 0; i < currentArgs.length; i++) {
result = args[i + 1](result)
}
return result
}
@alersenkevich
alersenkevich / what-color-to-write.js
Last active March 2, 2020 12:17
determine luminance by hex color
// HEX to RGB function
const hexToRgb = hex =>
hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => `#${r + r + g + g + b + b}`)
.substring(1)
.match(/.{2}/g)
.map(x => parseInt(x, 16))
// Determine relation of luminance in color
const luminance = (r, g, b) => {
const a = [r, g, b].map((v) => {
@alersenkevich
alersenkevich / grab.js
Last active November 23, 2017 19:19
simple function for grabbing content inside div with hidden overflow
function grabStage(e) {
const stage = document.getElementById('large-stage-container')
const { layerX: endX, layerY: endY } = e
const { x: startX, y: startY } = window.grabCoords // this coords are coords from the event.layer(X-Y) and we got them while first mousedown on stage
const distance = { x: Math.abs(endX - startX), y: Math.abs(endY - startY) }
if (!distance.x && !distance.y) return
const direction = {
x: (endX < startX) ? 'right' : 'left',
y: (endY < startY) ? 'down' : 'up',
}