Skip to content

Instantly share code, notes, and snippets.

View koyta's full-sized avatar

Andrei Khlivniuk koyta

  • Munich, Germany
View GitHub Profile
@koyta
koyta / 27.md
Created May 25, 2017 10:52
Errors

Обработка исключений

Error содержит:

  • .name
  • .message
  • .toString() // name + ': ' + message
  • .stack — string где произошла ошибка (не стандарт)
@koyta
koyta / dummy.js
Created November 28, 2017 15:58
dummy container
import React, {Component} from 'react'
import Dummy from 'Components/Main/Dummy'
import _ from 'lodash'
const imgToRight = (current, imageCount) => {
return current === 1 ? imageCount : (current - 1) % imageCount
}
const imgToLeft = (current, imageCount) => {
return 1 + current % imageCount
}
@koyta
koyta / dummy-component.js
Created November 28, 2017 16:00
dummy component
import React from "react";
const path = "http://194.87.239.90/fabric/images/3D/mannequin/1600x1600/";
const Dummy = props => {
const imgs = [];
for (let i = 1; i < props.imageCount + 1; i++) {
imgs.push(
<img
key={i}
@koyta
koyta / server.js
Created February 14, 2018 23:29
node server js
const express = require('express')
const cors = require('cors')
const localWebSocketServer = require('./localWSServer')
const app = express()
const port = 5000
const localWSS = new localWebSocketServer(8080);
@koyta
koyta / websocket.js
Created February 14, 2018 23:31
custom websocket server class definition
const WebSocket = require('ws')
const {
axiosBA,
publicKey
} = require('./axios');
const {
WEBSOCKET_TICKER_URL
} = require('./constants')
class localWebSocketServer {
import * as React from 'react';
import axios from 'axios';
import { ChartData } from 'chart.js';
import ChartRT from '../../components/ChartRT';
import { inject, observer } from 'mobx-react';
import { ChartContainerProps, ChartRTState } from '../../interfaces';
import * as ws from 'ws';
@inject('store') @observer
class ChartRTContainer extends React.Component<ChartContainerProps, ChartRTState> {
@koyta
koyta / package.json
Created February 14, 2018 23:36
Client package.json
{
"name": "charts",
"version": "0.1.0",
"private": true,
"dependencies": {
"chart.js": "^2.7.1",
"crypto-js": "^3.1.9-1",
"mobx": "^3.4.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
@koyta
koyta / formatMoney.js
Created October 7, 2018 10:20
Format money
function formatMoney(amount, decimalCount = 2, decimal = '.', thousands = ',') {
try {
decimalCount = Math.abs(decimalCount);
decimalCount = isNaN(decimalCount) ? 2 : decimalCount;
const negativeSign = amount < 0 ? '-' : '';
let i = parseInt((amount = Math.abs(Number(amount) || 0).toFixed(decimalCount))).toString();
let j = i.length > 3 ? i.length % 3 : 0;
@koyta
koyta / checkDevice.js
Created January 29, 2019 08:21
Checking device for server-side rendering
import smoothscroll from 'smoothscroll-polyfill';
export const DEVICE_TYPE = {
MOBILE: 'mobile',
MOBILE_BIG: 'mobile-big',
TABLET: 'tablet',
TABLET_BIG: 'tablet-big',
LAPTOP: 'laptop',
DESKTOP: 'desktop',
};
@koyta
koyta / index.js
Created February 27, 2019 14:03
next js redux use
import React from "react";
import { bindActionCreators } from "redux";
import { startClock, addCount, serverRenderClock } from "../store";
import { connect } from "react-redux";
class Counter extends React.Component {
static getInitialProps({ store, isServer }) {
store.dispatch(serverRenderClock(isServer));
store.dispatch(addCount());