Skip to content

Instantly share code, notes, and snippets.

View istarkov's full-sized avatar
💭
I need snow, now!

Ivan Starkov istarkov

💭
I need snow, now!
View GitHub Profile
@istarkov
istarkov / 00 README.md
Last active April 2, 2024 20:18
How to style React components

How to style React components

If you use sass and css-modules and want to restyle some base component without changing its code. (base component already use css-modules and exposes styles property)

I know two way how to do it.

  1. Using composes css-modules operator. Just extend classes you need, then in javascript code combine both styles as {...baseStyle, ...myStyleSimple}

Similar js toExponential method, but returns result in power format, instead of Xe-1 it returns X⋅10⁻¹

Usage example:

console.log(toPower(3, 111)); // out 1.110⋅10²
console.log(toPower(3, 0.00000000000000123)); //out 1.230⋅10⁻¹⁵
@istarkov
istarkov / serialize.js
Last active August 8, 2023 20:59
Serialize promise calls (run promises sequentially)
// promise
const sleep = (timeout, v) => new Promise(r => setTimeout(() => r(v), timeout));
// series to call
const series = [() => sleep(1000, 1), () => sleep(1000, 2), () => sleep(1000, 3)];
// serialize
const r = series
.reduce(
(m, p) => m.then(v => Promise.all([...v, p()])),
Promise.resolve([])

How to setup atom with nuclide plugins.

You need to install next packages

  • hyperclick
  • nuclide-diagnostics-store
  • nuclide-diagnostics-ui
  • nuclide-flow

You need to add .flowconfig

// no string get
const get = (fn, def) => {
try {
return fn();
} catch (e) {
return def;
}
};
// usage example
// How to check array access
const arr = [];
const proxiedArr = new Proxy(arr, {
set(target, name, value) {
console.log(target, name, value);
// console.trace();
target[name] = value;
return value;
},

The problem: old ubuntu does not support chrome http2 as chrome uses APLN which is exists in openssl ^1.0.2h

create file /etc/apt/sources.list.d/nginx.list and add lines

deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx
@istarkov
istarkov / unknown.md
Last active September 19, 2016 17:06
  • insist - настаивать
  • apart - кроме
  • posess - обладать
  • considerably - изрядно, конкретно
  • disclose раскрыть (секрет)
  • complain жаловаца
  • urgent срочный
// change output type of withProps
// from `HOC<A & B, B>` to `HOC<{ ...$Exact<B>, ...A }, B>`
type EnhancedCompProps = { b: number }
const enhancer2: HOC<*, EnhancedCompProps> = compose(
withProps(({ b }) => ({
b: `${b}`,
})),
withProps(({ b }) => ({
// $ExpectError The operand of an arithmetic operation must be a number
/* @flow */
import React from 'react'
import { compose, defaultProps, withProps } from 'recompose'
import type { HOC } from 'recompose';
// type of Enhanced component props
type EnhancedComponentProps = {
text?: string,
};