Skip to content

Instantly share code, notes, and snippets.

View Mustafa-Omran's full-sized avatar
💭
I may be slow to respond.

Mustafa Omran Mustafa-Omran

💭
I may be slow to respond.
  • Egypt
View GitHub Profile
@Mustafa-Omran
Mustafa-Omran / cache-interceptor.ts
Created February 13, 2023 11:15
Caching - Passing Context to HTTP Interceptors
const CACHE_IT = new HttpContextToken<boolean>(() => false);
export function cacheIt() {
return new HttpContext().set(CACHE_IT, true);
}
@Injectable()
export class CacheInterceptor implements HttpInterceptor {
intercept(request: HttpRequest, next: HttpHandler): Observable<HttpEvent> {
@Mustafa-Omran
Mustafa-Omran / angular-log-service.ts
Created January 22, 2023 12:58
Angular Log Service
import { Injectable } from "@angular/core";
export enum LogLevel {
DEBUG,
INFO,
ERROR,
}
@Injectable()
export class LogService {
minimumLevel: LogLevel = LogLevel.INFO;
@Mustafa-Omran
Mustafa-Omran / itersection.ts
Last active August 18, 2022 16:25
Intersection of two Strings JS
private itersection(textOne: string, textTwo: string): string {
let textOneIndex: number = 0;
let textTwoIndex: number = 0;
let matchedText: string = '';
textOne = textOne.toLowerCase();
textTwo = textTwo.toLowerCase();
while (textOneIndex < textOne.length && textTwoIndex < textTwo.length) {
if (textOne[textOneIndex] < textTwo[textTwoIndex]) {
@Mustafa-Omran
Mustafa-Omran / build-date.js
Created April 13, 2022 10:57
Angular - Save Build Time At Package.json
const { writeFileSync } = require('fs')
const { join } = require('path')
const BUILD_DATE_TIME_STAMP_PATH = join(__dirname, 'build-date.json');
const createBuildDate = {
buildDate: new Date()
}
writeFileSync(TIME_STAMP_PATH, JSON.stringify(createBuildDate, null, 2));
@Mustafa-Omran
Mustafa-Omran / localstorage-changes-angular.ts
Created March 14, 2022 17:39
Angular - Listen to local storage changes angular
import { Component, HostListener, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@Mustafa-Omran
Mustafa-Omran / update.service.ts
Created March 14, 2022 11:08
Angular - Service Worker (Dealing With Updates)
import { Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { SwUpdate } from '@angular/service-worker';
@Injectable()
export class UpdateService {
constructor(private swUpdate: SwUpdate,
private snackbar: MatSnackBar) {
this.swUpdate.available.subscribe(event => {
@Mustafa-Omran
Mustafa-Omran / no-white-space.ts
Created March 14, 2022 09:16
Angular - No white spaces
import { FormControl } from "@angular/forms";
export function noWhitespaceValidator(control: FormControl) {
const isWhitespace = (control.value || '').trim().length === 0;
const isValid = !isWhitespace;
return isValid ? null : { 'whitespace': true };
}
@Mustafa-Omran
Mustafa-Omran / language.service.ts
Created February 28, 2022 07:56
Angular - Language Service
import { Injectable, Inject } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';
import { DOCUMENT } from '@angular/common';
@Injectable({
providedIn: 'root'
})
export class LanguageService {
private readonly DEFAULT_LANGUAGE = 'en';
@Mustafa-Omran
Mustafa-Omran / autocomplete-off.html
Created February 23, 2022 12:36
HTML - Disable autocomplete suggestions
<input type="text" autocomplete="off" autocomplete="chrome-off">
@Mustafa-Omran
Mustafa-Omran / demo.html
Last active February 23, 2022 15:11
Angular - Custom directive to accept only positive numbers within inputs
<!-- keep it as text to hide arrow up and down -->
<!-- user can add negative numbers if type number -->
<input type="text" positiveNumbers>