Skip to content

Instantly share code, notes, and snippets.

@walidum
walidum / server.js
Created April 30, 2021 17:56
node express server
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(__dirname + '/dist/<FOLDER_NAME>'));
app.get('/*', (req,res,next) => {
res.sendFile(path.join(__dirname + '/dist/dictionary/index.html'));
});
@walidum
walidum / package.json
Created April 30, 2021 17:58
package.json
"start": "node server.js",
"heroku-postbuild": "ng build --prod"
@walidum
walidum / package.json
Created April 30, 2021 17:59
engines
"engines": {
"node": "14.15.3",
"npm": "6.14.9"
},
@walidum
walidum / auth.interceptor.ts
Created April 30, 2021 18:18
auth.interceptor.ts
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Observable } from 'rxjs';
import { AuthenticationService } from '@app/_services';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(private authenticationService: AuthenticationService) { }
@walidum
walidum / authentication.service.ts
Created April 30, 2021 18:21
authentication.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { BehaviorSubject, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { environment } from '@environments/environment';
import { User } from '@app/_models';
@Injectable({ providedIn: 'root' })
export class AuthenticationService {
@walidum
walidum / app.module.ts
Last active April 30, 2021 18:24
app.module.ts interceptors
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { AppComponent } from './app.component';
import { appRoutingModule } from './app.routing';
import { AuthInterceptor, ErrorInterceptor } from './_helpers';
@walidum
walidum / error.interceptor.ts
Last active May 2, 2021 17:36
error.interceptor.ts
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor
} from '@angular/common/http';
import {Observable, throwError} from 'rxjs';
import { AuthenticationService } from '@app/_services';
import {catchError} from 'rxjs/operators';
@walidum
walidum / index.js
Last active May 3, 2021 09:36
How to call reduce on an array of objects to sum their properties?
const arr = [{x:1}, {x:2}, {x:4}];
const res = arr.reduce((acc, item) => acc + item.x, 0);
console.log(res); //=> 7
@walidum
walidum / pom.xml
Created May 4, 2021 10:42
WebFlux
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Setter
@Getter
@NoArgsConstructor
public class Person {
private int id;