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 / .cpp
Created October 20, 2017 07:02
oserver realization
#include <iostream>
#include <string>
#include <list>
using namespace std;
class SupervisedString;
class IObserver
{
public:
@alersenkevich
alersenkevich / applyMiddleware.js
Last active October 26, 2017 09:50
applyMiddleware function
const dummy = ws => ws
export const applyMiddlewareForWebSocket = (ws, ...fnList) => {
let tmp = ws
fnList.forEach((fn, index) => {
tmp = fn(tmp, fnList[index + 1] || dummy)
})
}
@alersenkevich
alersenkevich / webpack.config.js
Last active October 26, 2017 16:36
webpack config for pixi.js
const path = require('path')
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js',
},
module: {
@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',
}
@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 / .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 / .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 / .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 / .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 / 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)