Skip to content

Instantly share code, notes, and snippets.

@raviagheda
raviagheda / mock-resizeobserver-jest.md
Created April 9, 2024 06:10
Mock ResizeObserver in JEST
global.ResizeObserver = jest.fn().mockImplementation(callback => {
  let elements: any[] = [];
  
  const observe = jest.fn(element => {
    elements.push(element);
    // Here you can simulate setting height and width
    callback([{ target: element, contentRect: { width: 100, height: 200 } }]);
  });
form: FormGroup = new FormGroup({
    email: new FormControl('', [Validators.required], [this.customValidator()])
  })

  customValidator(): AsyncValidatorFn {
    return (control: AbstractControl): Observable<ValidationErrors | null> => {
      return this.loginService.checkUserExist({value: control?.value, type: 1})
      .pipe(map((res: {status: boolean, message: string}) => {
 return res?.status ? null : { duplicate: true };
const signalTraps = ['SIGTERM', 'SIGINT', 'SIGUSR2'];

signalTraps.forEach(type => {
  process.once(type, async () => {
    try {
        console.log("On Exist");
        // perform operations here
        // await consumer.disconnect()
 } finally {
@raviagheda
raviagheda / json-to-csv.md
Created August 30, 2022 11:53
Generate CSV from JSON Object

Install npm package objects-to-csv

import * as ObjectsToCsv from 'objects-to-csv';

const createCSV = async (data: any, name: string) => {
    const csv = new ObjectsToCsv(data);
 await csv.toDisk(path.join(__dirname, '../data/processed-csvs/' + name) );
import { Directive, ElementRef, OnInit, AfterViewInit } from '@angular/core';

@Directive({
  selector: '[appAutofocus]'
})
export class AutofocusDirective implements OnInit, AfterViewInit {


 constructor(private elementRef: ElementRef) { }
@raviagheda
raviagheda / nginx-link-port.md
Last active July 24, 2023 06:25
Nginx configuration setup
@raviagheda
raviagheda / angular-firebase-cicd.md
Created December 18, 2021 21:05
Angular Firebase CICD

Angular Firebase CICD

Configure firebase token

Apply command firebase login:ci

Pipe line

name: Build and deploy
@raviagheda
raviagheda / github-action-ssh.md
Last active May 2, 2024 10:06
Github Action with EC2 using SSH