Skip to content

Instantly share code, notes, and snippets.

import { Injectable } from '@angular/core';
import { BehaviorSubject, Subscription, Observable } from 'rxjs';
import { interval } 'rxjs/operators';
@Injectable()
export class IntervalService {
private subject = new BehaviorSubject<number>(-1);
private subscription: Subscription;
readonly observable$ = this.subject.asObservable();
@harbirchahal
harbirchahal / nginx_stop.bat
Last active April 28, 2021 10:39
Stop Nginx Process
@echo off
cd /nginx
taskkill /f /IM nginx.exe
exit
@harbirchahal
harbirchahal / nginx_restart.bat
Last active April 28, 2021 10:39
Restart Nginx Process
@echo off
cd /nginx
taskkill /f /IM nginx.exe
start nginx
exit
@harbirchahal
harbirchahal / unauthorized.interceptor.ts
Last active May 14, 2019 14:15
Unauthorized Request HTTP Interceptor
import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { tap } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class UnauthorizedHttpInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler) {
@harbirchahal
harbirchahal / timeout.interceptor.ts
Last active May 14, 2019 14:15
Request Timeout HTTP Interceptor
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { empty, TimeoutError } from 'rxjs';
import { timeout, catchError } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class RequestTimeoutHttpInterceptor implements HttpInterceptor {
@harbirchahal
harbirchahal / app.module.ts
Created May 15, 2019 11:54
Request Timeout HTTP Interceptor (Header)
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { RequestTimeoutHttpInterceptor, DEFAULT_TIMEOUT } from './interceptors';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
@harbirchahal
harbirchahal / MaxHeap.java
Last active April 28, 2021 10:38
DS: Max Heap
import java.util.Arrays;
/**
* MAX_HEAP: the root will always be the largest value
*/
public class MaxHeap {
private int[] data;
private int size;
public MaxHeap(int size) {
@harbirchahal
harbirchahal / array_util.ts
Last active November 19, 2019 08:39
Simplest implementation of array utility functions.
const map = ([head, ...tail], fn) =>
typeof head === 'undefined' ?
[] :
[fn(head), ...map(tail, fn)];
const reduce = ([head, ...tail], fn, value) =>
typeof head === 'undefined' ?
value :
reduce(tail, fn, fn(value, head));
@harbirchahal
harbirchahal / constructor_function.js
Last active November 25, 2019 09:02
Constructor OO pattern in JavaScript
/** Person pseudo class. */
const Person = (function () {
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.alias = function () {
return this.firstName.charAt(0) + this.lastName.charAt(0);
}
@harbirchahal
harbirchahal / String.java
Last active February 26, 2020 18:20
Mock implementation of String functions
public class String {
public static boolean contains(String s, String t) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == t.charAt(0)) {
int j = 1;
for (; j < t.length(); j++) {
if (t.charAt(j) != s.charAt(i + j)) {
break;
}