Skip to content

Instantly share code, notes, and snippets.

View Artawower's full-sized avatar
🤪
Working from home

Art Artawower

🤪
Working from home
View GitHub Profile
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor, HttpResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, of, timer } from 'rxjs';
import { mergeMap, tap, retryWhen, delayWhen } from 'rxjs/operators';
@Injectable()
/**
* This class is used to intercept network errors with status 500+ and some 400s
* then add failed request to the queue and try to resend it after
* some times.
import {
Directive,
ElementRef,
EmbeddedViewRef,
EventEmitter,
HostListener,
Injectable,
Input,
OnDestroy,
OnInit,
#! /bin/sh
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
FILES_LIST=$(git diff --name-only ${CURRENT_BRANCH} $(git merge-base ${CURRENT_BRANCH} master) | awk '/\.ts$/ {print "--lint-file-patterns="$0}')
npm run lint -- <project_name> $FILES_LIST
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'dateformat',
})
export class DateFormatPipe implements PipeTransform {
transform(value: string): string {
const valDate = new Date(value);
if (this.isToday(valDate)) {
return `Сегодня`;
@Artawower
Artawower / retry-with-delay.rxjs.ts
Last active November 10, 2021 13:43
Rxjs retry operator with dynamic delay between attempts
import { Observable, MonoTypeOperatorFunction, of } from "rxjs";
import { retryWhen, delay, take, catchError, concatMap } from "rxjs/operators";
let globalCounter = 0;
const emitter$ = new Observable((subscriber) => {
if (globalCounter >= 5) {
subscriber.next("Heey, finally i'am work!");
subscriber.complete();
}