Skip to content

Instantly share code, notes, and snippets.

View Dremora's full-sized avatar

Kirill Korolyov Dremora

View GitHub Profile
import moment from 'moment';
export const EMAIL_REGEXP = /[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])/;
const isInRange = (date: moment, [from, to]: [moment, moment]): boolean =>
date.isSameOrAfter(from, 'day') && date.isSameOrBefore(to, 'day');
type ValidatorReturn = string | null;
type Validator<T> = (value: T) => ValidatorReturn;
type Predicate<T> = (value: T) => boolean;
pg_dump --format=custom --no-acl --no-owner -U USER1 -h HOST1 DATABASE1 > database.dump
pg_restore --verbose --clean --no-acl --no-owner -U USER2 -h HOST2 -d DATABASE2 database.dump
@Dremora
Dremora / context.ts
Last active October 14, 2020 12:43
Prohibit using React context without provider
import { createContext } from 'react';
interface SystemStatus {
isOnline: boolean;
}
const SystemStatusContext = createContext<SystemStatus>({
get isOnline(): never {
throw new Error('Used outside of SystemStatusContext');
}
@Dremora
Dremora / error.ts
Created December 15, 2021 20:32
TypeScript runtime error due to the lack of exact types
const foo = { a: 1, b : {}}
const bar: { a: number} = foo;
const baz: { [a: string]: number} = bar;
const b = baz['b'];
if (typeof b !== 'undefined') {
console.log(b.toFixed(2))
}
@Dremora
Dremora / app.js
Last active February 8, 2022 11:16
ESLint configuration
const path = require('path');
module.exports = {
parserOptions: {
tsconfigRootDir: __dirname, // required for VS Code
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true, // required for TS project references
},
extends: ['./frontend-app'], // or backend
settings: {
'import/resolver': {
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';
export const rule = ESLintUtils.RuleCreator.withoutDocs({
meta: {
docs: {
description: 'ban date comparison using ==, ===, !=, !==',
recommended: 'warn',
},