Skip to content

Instantly share code, notes, and snippets.

View FFKL's full-sized avatar
🦔
This is The Hedgehog!

Dmitrii Korostelev FFKL

🦔
This is The Hedgehog!
View GitHub Profile
@FFKL
FFKL / page.decorator.ts
Last active August 17, 2020 17:56
Page decorator which wrap ngOnDestroy and ngOnInit functions for change global layout structure. Works in Angular 9 + Ivy + AOT.
import { Injector, NgModule, ɵComponentDef as ComponentDef, ɵNG_COMP_DEF } from '@angular/core';
import { LayoutType } from '@constants/layout';
import { GlobalLayoutStore } from '@services/store/global-layout.store';
const NG_COMP_DEF = ɵNG_COMP_DEF as 'ɵcmp';
interface Options {
layout?: LayoutType;
}
export function Required(target: { [prop: string]: any }, propertyKey: string) {
Object.defineProperty(target, propertyKey, {
get() {
throw new Error(`Attribute ${propertyKey} is required`);
},
set(value) {
Object.defineProperty(
target,
propertyKey,
{
@FFKL
FFKL / cell-ellipsis.css
Last active September 2, 2025 15:54
Auto-resizable ellipsis without fixed width 😮
.ellipsis {
position: relative;
}
.ellipsis:before {
content: ' ';
visibility: hidden;
}
.ellipsis span {
function debounceTime<T extends (...args: any) => any>(callback: T, time: number) {
let timeout: NodeJS.Timeout | null = null;
return (...args: Parameters<T>) => {
timeout != null && clearTimeout(timeout);
timeout = setTimeout(
() => {
timeout = null;
callback.apply(null, args);
},
@FFKL
FFKL / example.html
Last active May 5, 2020 19:13
Numbers range component
<sv-numbers-range>
<input svThreshold placeholder="Min price" formControlName="min" type="text">
<input svThreshold placeholder="Max price" formControlName="max" type="text">
</sv-numbers-range>
export type Modify<T, R extends { [key in keyof T]?: any }> = Omit<T, keyof R> & R;
@FFKL
FFKL / event-bus.service.ts
Created April 14, 2020 12:29
Angular pubSub service
import { Injectable } from '@angular/core';
import { Observable, ReplaySubject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class EventBusService {
private readonly events: { [eventName: string]: ReplaySubject<any> } = {};
public sub(event: string): Observable<any> {
@FFKL
FFKL / angular-clock.component.ts
Last active April 15, 2020 19:58
Single-file clock for admin panel header
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core';
import { timer, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@Component({
selector: 'app-clock',
template: `{{ time$ | async | date:'medium' }}`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
})
@FFKL
FFKL / package.json
Created March 26, 2020 15:05
Several versions of same package in dependencies.
{
"dependencies": {
"package": "npm:[email protected]",
"package-1.5": "npm:[email protected]",
"package-1.6": "npm:[email protected]",
}
}
// @flow
class Animal {}
class Dog extends Animal {
bark() {}
}
class Cat extends Animal {
meow() {}
}