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

Challenge

You have a json file with following structure (example)

[
  { 
    "id": 1,
    "title": "Hello",
 "description": "World"
@istarkov
istarkov / esbuild.js
Created May 22, 2021 13:38
esbuild node app setup for latest stable node > 14.16.0
// same as `yarn esbuild index.ts src/**/*.ts --platform=node --format=esm --tsconfig=./tsconfig.json --outdir=dist --watch`
// but with respawn server on change
import esbuild from 'esbuild';
import fg from 'fast-glob';
import { spawn } from 'child_process';
const entryPoints = await fg(['index.ts', 'src/**/*.ts']);
const dev = process.env.NODE_ENV !== 'production';
@istarkov
istarkov / peg parser
Last active March 14, 2021 16:59
Icu messages format pegjs parser
/*Parses ICU messages format https://messageformat.github.io/messageformat/guide/
like
{from} - {to} {results, plural,
one { # result }
many { # results }
} text {vr} rmm
{s, select,
man { He is "#"#"#" }
woman { She is # }
}

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 / question.md
Last active March 5, 2018 22:00
Need help

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)
/* @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 =>
/* @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)} />
}
type MyComponentProps = HOCBase<typeof myEnhancer>
class MyComponent extends React.Component<MyComponentProps> {
render() ...
}
const MyEnhancedComponent = myEnhancer(MyComponent)
// Extract type from any enhancer
type HOCBase_<A, B, C: HOC<A, B>> = A
type HOCBase<C> = HOCBase_<*, *, C>
/* @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,
};