Skip to content

Instantly share code, notes, and snippets.

View Dremora's full-sized avatar

Kirill Korolyov Dremora

View GitHub Profile
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',
},
@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': {
@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 / 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');
}
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
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;
@Dremora
Dremora / typescript-json-decoder-example.ts
Last active March 29, 2020 20:36
typescript-json-decoder
import { Decoder, array, decode, lazy, object, oneOf, string } from "./typescript-json-decoder";
type TreeEntry = string | { name: string; contents: TreeRoot };
type TreeRoot = TreeEntry[];
function getTreeEntryDecoder(): Decoder<TreeEntry> {
return oneOf<TreeEntry>(
string,
object({ contents: lazy(getTreeDecoder), name: string })
);
// @flow
import React, { Component, type Node } from 'react';
import PropTypes from 'prop-types';
type RenderFn<T> = (value: T) => Node;
export type ProviderProps<T> = {
value: T,
children?: Node
};
@Dremora
Dremora / Dockerfile
Last active April 10, 2017 13:12
Techbikers Dockerfile
FROM python:2.7
ADD . /app
WORKDIR /app
RUN pip install -r requirements.txt
RUN cp server/settings/local.py.skel server/settings/local.py
RUN sed -i "s/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = ['localhost']/g" server/settings/local.py
RUN SECRET_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1); sed -i "s/SECRET_KEY = ''/SECRET_KEY = '$SECRET_KEY'/g" server/settings/local.py
RUN mkdir logs
@Dremora
Dremora / components.my-component.js
Created January 23, 2017 15:09
Event bubbling in integration tests
import Ember from 'ember';
export default Ember.Component.extend({
clicked: 0,
actions: {
clicked() {
this.set('clicked', this.get('clicked') + 1);
}
}