Skip to content

Instantly share code, notes, and snippets.

View imran3's full-sized avatar

Imran Azam imran3

  • UK
View GitHub Profile
@imran3
imran3 / retry-http-errors.interceptor.spec.ts
Last active November 16, 2022 15:14
Retry http errors mechanism in Angular
import { HttpClient, HttpErrorResponse, HttpResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { AppConfig } from '../../services/app-config/app-config.interface';
import { AppConfigService } from '../../services/app-config/app-config.service';
import { MOCK_APP_CONFIG } from '../../services/app-config/mock/get-config.mock';
import { RetryHttpErrorsInterceptor } from './retry-http-errors.interceptor';
describe('RetryHttpErrorsInterceptor', () => {
@imran3
imran3 / AppConfigService.js
Last active October 4, 2021 20:59
Runtime configuration for Angular apps
//AppConfig.d.ts
export interface AppConfig {
appInsightsKey: string;
}
//AppConfigService.ts
@Injectable()
export class AppConfigService {
private config: AppConfig;
loaded = false;
@imran3
imran3 / ApplicationInsightsErrorHandler.js
Last active October 1, 2021 20:21
Application Insights snippet for Angular apps
@Injectable()
export class ApplicationInsightsErrorHandler extends ErrorHandler {
constructor(private injector: Injector) {
super();
}
handleError(error: any): void {
// injecting ApplicationInsightService via injector to avoid infinite loop in case
// error is with service itself
this.injector.get<ApplicationInsightsService>(ApplicationInsightsService).logException(error);
@imran3
imran3 / SumOfDigits.ts
Last active September 23, 2020 10:57
Review a sequence of digits and find the sum of all digits that match the next digit in the list.
/*
Problem:
Review a sequence of digits and find the sum of all digits that match the next digit in the list.
The list is circular, so the digit after the last digit is the first digit in the list.
Input samples:
1122 produces a sum of 3 (1 + 2) because the first digit (1) matches the second digit and the third digit (2) matches
the fourth digit.
1111 produces 4 because each digit (all 1) matches the next.
1234 produces 0 because no digit matches the next.

Keybase proof

I hereby claim:

  • I am imran3 on github.
  • I am imran3 (https://keybase.io/imran3) on keybase.
  • I have a public key whose fingerprint is 290A 0FA8 04EB CE36 7B90 571F 9B44 2CC2 9220 AE1D

To claim this, I am signing this object: