Skip to content

Instantly share code, notes, and snippets.

View SerhiiSerdiuk's full-sized avatar

Serhii Serdiuk SerhiiSerdiuk

View GitHub Profile
@SerhiiSerdiuk
SerhiiSerdiuk / map.pipe.ts
Created May 18, 2021 09:07 — forked from yannickglt/map.pipe.ts
Generic pure Angular pipe
// A safe way to call methods in templates
// Live demo @ https://stackblitz.com/edit/angular-generic-map-pipe
import { Pipe, PipeTransform } from "@angular/core";
// Methods passed to the map pipe cannot (and should not) use the `this` keyword from components. Otherwise, it would not be a pure pipe.
@Pipe({ name: "map" })
export class MapPipe implements PipeTransform {
public transform<T, R>(
thisArg: T,
project: (t: T, ...others: any[]) => R,
@SerhiiSerdiuk
SerhiiSerdiuk / auto-unsub-decorator.ts
Created January 18, 2020 15:47
Angular unsubscribe decorator
fnction AutoUnsub(obs$ = []) {
return function(constructor: any) {
const orig = constructor.prototype.ngOnDestroy
constructor.prototype.ngOnDestroy = function() {
for(const prop in this) {
const property = this[prop]
if(typeof property.unsubscribe === "function" && !obs$.includes(property))
obs$.push(property)
}
for(const ob$ of obs$) {
function drawNestedSetsTree(data, node) {
const ul = document.createElement('ul');
function nodeHasChildren(node) {
return node.right - node.left == 1 ? false : true;
}
function getChildren(arr, node) {
const children = [];
let childIndex = node.left + 1;
@SerhiiSerdiuk
SerhiiSerdiuk / 0_reuse_code.js
Created November 5, 2016 17:04
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console

Font Face

A mixin for writing @font-face rules in SASS.

Usage

Create a font face rule. Embedded OpenType, WOFF2, WOFF, TrueType, and SVG files are automatically sourced.

@include font-face(Samplino, fonts/Samplino);