This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//READ MORE IN THIS ARTICLE https://morioh.com/a/782c0022755e/using-bcrypt-to-hash-passwords-in-nodejs EXPECIALLY PRE-REQUISITE | |
const bcrypt = require("bcrypt") | |
const saltRounds = 10 | |
const password = "Admin@123" | |
//Password encryption + explicit Salt | |
bcrypt | |
.genSalt(saltRounds) | |
.then(salt => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ORIGINAL CODE BY CHAU: https://gist.github.com/eneajaho/33a30bcf217c28b89c95517c07b94266 | |
import { isSignal, Signal, untracked } from '@angular/core'; | |
import { toObservable, toSignal } from '@angular/core/rxjs-interop'; | |
import { | |
combineLatest, | |
distinctUntilChanged, | |
from, | |
isObservable, | |
ObservableInput, | |
of, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//INSPIRED BY https://medium.com/ngconf/make-trackby-easy-to-use-a3dd5f1f733b | |
import { Directive, inject, Provider } from "@angular/core"; | |
import { ngForOf, NgIterable } from "@angular/common"; | |
@Directive({ | |
selector: "[ngForTrackById]", | |
standalone: true | |
}) | |
export class NgForTrackByIdDirective<T extends { id: string | number }> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Helper function to handle async call (Observable generator with strategy + safe retry if error) to push value to Signal - useful for State Management with Signal | |
//READ MORE https://medium.com/@eugeniyoz/application-state-management-with-angular-signals-b9c8b3a3afd7 | |
//ORIGINAL DOCS (NgRx component-store effect) https://ngrx.io/guide/component-store/effect#effect-method | |
import { isObservable, Observable, of, retry, Subject, Subscription } from 'rxjs'; | |
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; | |
import { DestroyRef, inject } from '@angular/core'; | |
/** | |
* This code is a copied `ComponentStore.effect()` method from NgRx and edited to: | |
* 1) be a standalone function; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ORIGINAL CODE https://github.com/jscutlery/devkit/tree/main/packages/operators | |
import { | |
MonoTypeOperatorFunction, | |
Observable, | |
ObservableNotification, | |
OperatorFunction, | |
ReplaySubject, | |
} from 'rxjs'; | |
import { debounce, map, materialize, scan, startWith } from 'rxjs/operators'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef } from "@angular/core"; | |
import { AuthService } from "./auth.service"; | |
import { Subscription, Subject } from "rxjs"; | |
@Directive({ | |
selector: "[hasRole]", | |
standalone: true | |
}) | |
export class HasRoleDirective { | |
constructor( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ORIGINAL CODE BY https://twitter.com/mattpocockuk/status/1633064377518628866?s=20 | |
/** | |
* First, create a type helper that represents | |
* the result that we'll get from our safe function | |
*/ | |
export type SafeResult<T> = | |
| { | |
ok: true; | |
value: T; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ORIGINAL CODE INSPIRED BY Wassim Chegham https://twitter.com/manekinekko/status/1624440889216057347/photo/1 | |
export function fromReadableStream( | |
stream: ReadableStream, | |
signal?: AbortSignal, | |
writableStrategy?: QueuingStrategy, | |
readableStrategy?: QueuingStrategy | |
): Observable<string> { | |
const createTextDecoderStream = ()=> new TextDecoderStream(); | |
const transformer = () => new TransformStream( | |
{ transform(chunk, controller) { controller.enqueue(chunk); } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"@Input Observable for Angular": { | |
"prefix": "in$", | |
"description": "Create an Observable @Input", | |
"body": [ | |
"#${1:prop} = new BehaviorSubject<${2:type}|undefined>(undefined);", | |
"protected ${1:prop}\\$ = this.#${1:prop}.pipe(filter(p=>p!==undefined));", | |
"@Input() set ${1:prop}(value: ${2:type}) {", | |
"\t$0//if (value!==this.${1:prop}) //eventual validation logic", | |
"\tthis.#${1:prop}.next(value);", | |
"}", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ChangeDetectionStrategy, Directive, EventEmitter, Input, OnDestroy, Output } from "@angular/core"; | |
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms"; | |
import { Subject } from "rxjs"; | |
@Directive(/*{ | |
selector: "base-formctrl", | |
standalone: true, | |
// templateUrl: "./n-date-picker.component.html", //IL TEMPLATE VA SPECIFICATO SULLA @Component OSSIA LA CLASSE EREDITATA | |
// styleUrls: ["./n-date-picker.component.css"], //GLI STYLE VANNO SPECIFICATI SULLA @Component OSSIA LA CLASSE EREDITATA | |
// providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: NBaseFormCtrlComponent, multi: true }], //PURTROPPO QUESTO NON FUNZIONA SULLA ABSTRACT DEVO FARE IL PROVIDER NELLA CLASSE EREDITARE |