Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I need snow, now!

Ivan Starkov istarkov

💭
I need snow, now!
View GitHub Profile
View question.md

I want to hold ordering of some items in SQL, like field in a table index: 0,1,2,3,4,... and I have operation moveItem

If I want to move item from index: 1 to index: 3 I can do

delete from table where index = 1;
update table set index = index - 1 where index > 1
update table set index = index + 1 where index >=3
insert into table (index) values (3)
View classBasedEnhancer.js
/* @flow */
import * as React from 'react'
import { compose, withProps } from 'recompose'
import type { HOC } from 'recompose'
// Example of very dirty written fetcher enhancer
function fetcher<Response: {}, Base: {}>(
dest: string,
nullRespType: ?Response
): HOC<{ ...$Exact<Base>, data?: Response }, Base> {
return BaseComponent =>
View simpleTypedEnhancer.js
/* @flow */
import * as React from 'react'
import { compose, withProps } from 'recompose'
import type { HOC } from 'recompose'
function mapProps<BaseProps: {}, EnhancedProps>(
mapperFn: EnhancedProps => BaseProps
): (React.ComponentType<BaseProps>) => React.ComponentType<EnhancedProps> {
return Component => props => <Component {...mapperFn(props)} />
}
View UseHocBase.js
type MyComponentProps = HOCBase<typeof myEnhancer>
class MyComponent extends React.Component<MyComponentProps> {
render() ...
}
const MyEnhancedComponent = myEnhancer(MyComponent)
View HOCBase.js
// Extract type from any enhancer
type HOCBase_<A, B, C: HOC<A, B>> = A
type HOCBase<C> = HOCBase_<*, *, C>
View enhancedBase.js
/* @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,
};
View withProps.js
// 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
View unknown.md
  • insist - настаивать
  • apart - кроме
  • posess - обладать
  • considerably - изрядно, конкретно
  • disclose раскрыть (секрет)
  • complain жаловаца
  • urgent срочный
View 01-howto-setup-nginx-with-http2-on-ubuntu-12-04.md

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
View proxy.js
// 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;
},
You can’t perform that action at this time.