Skip to content

Instantly share code, notes, and snippets.

View navix's full-sized avatar
❄️
Coding smart ;)

Oleksa Novyk navix

❄️
Coding smart ;)
View GitHub Profile
@navix
navix / local-storage.ts
Last active April 11, 2024 09:04
Angular LocalStorage/SessionStorage services. Universal (SSR) compatible.
import { Platform } from '@angular/cdk/platform';
import { Injectable } from '@angular/core';
import { MemoryStorage } from './memory-storage';
@Injectable({
providedIn: 'root',
})
export class LocalStorage implements Storage {
private readonly storage: Storage;
@navix
navix / NG_PRETTIER_SETUP.md
Last active September 12, 2023 02:36
My Prettier setup for Angular apps
$ npm i prettier prettier-plugin-css-order prettier-plugin-organize-attributes css-declaration-sorter -D

Create .prettierrc file:

{
  "printWidth": 120,
 "tabWidth": 2,
@navix
navix / readme.md
Last active August 4, 2023 09:02
TypeScript Deep Partial Interface

TypeScript Deep Partial Interface

export type DeepPartial<T> = T extends Function ? T : (T extends object ? { [P in keyof T]?: DeepPartial<T[P]>; } : T);

Before typescript@3.1

type DeepPartial = {
@navix
navix / readme.md
Created February 11, 2019 11:18
Docker image with Angular application

Docker image with Angular application

How to build a Docker image that serves Angular application (without Universal).

Build your application to the dist/app directory, then copy it into an image.

Dockerfile

FROM nginx:latest
@navix
navix / readme.md
Last active February 4, 2023 18:40
Typescript advanced built-in types
@navix
navix / text-to-speech.ts
Created July 17, 2020 16:58
google text-to-speech
import { existsSync, mkdirSync } from 'fs';
import { resolve } from 'path';
import { config } from '../config';
export async function processTextToSpeech(ssml: string, filename: string) {
// Check media dir
const dirPath = resolve(config.main.storePath);
if (!existsSync(dirPath)) {
mkdirSync(dirPath);
}
@navix
navix / async javascript.md
Created September 21, 2017 18:08 — forked from StevenACoffman/async javascript.md
Async Await in 7 seconds

Async / Await in 7 seconds

by Wassim Chegham (@manekinekko)

From this awesome animation, originally from this tweet

Callbacks (continuation passing style)

getData( a => {
	getMoreData(a, b => {
@navix
navix / nl2br.pipe.ts
Created January 5, 2023 20:04
nl2br pipe
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'nl2br',
standalone: true,
})
export class Nl2brPipe implements PipeTransform {
transform(text: string): string {
return Nl2brPipe.replace(text);
}
@navix
navix / readme.md
Last active November 23, 2022 09:18
Prevent leaving from any page using Router in Angular 7

Prevent leaving from any page using Router in Angular 7

Angular has CanDeactivate guard, but you have to declare it to each path in the routes configuration.

Valid until angular/angular#11836 will be done.

You can use CanActivateChild guard to prevent leaving from any component with single declaration.

leave-guard.service.ts

@navix
navix / readme.md
Created February 11, 2019 11:39
Wait for all animations to finish before :leave in Angular 7 (@angular/animations)

Wait for all animations to finish before :leave in Angular 7

Including child components.

@Component({
  ...
  animations: [
    trigger('host', [
 transition(':enter, :leave', [