Skip to content

Instantly share code, notes, and snippets.

View AlexAegis's full-sized avatar
🦔
ʕ•ᴥ•ʔ

Sandor AlexAegis

🦔
ʕ•ᴥ•ʔ
View GitHub Profile
@AlexAegis
AlexAegis / photoshop_cartesian.js
Created April 17, 2019 13:50
Photoshop layer permutator
/**
* Photoshop only accepts ExtendScript which is compliant to ECMA-262 (version 3)
*
* This script, when executed in Photoshop exports all the possible combinations of layers in the first group of the active activeDocument
* For example:
* If the top group has 2 subgroups, each having 2 layers
* this script will export 4 pictures with the following layers being visible:
* [0, 0]
* [0, 1]
* [1, 0]
@AlexAegis
AlexAegis / angular-megalistener.ts
Created April 22, 2019 21:50
Angular Megalistener - When you want to hear everything
@HostListener('abort', ['$event'])
@HostListener('afterprint', ['$event'])
@HostListener('animationend', ['$event'])
@HostListener('animationiteration', ['$event'])
@HostListener('animationstart', ['$event'])
@HostListener('beforeprint', ['$event'])
@HostListener('beforeunload', ['$event'])
@HostListener('blur', ['$event'])
@HostListener('canplay', ['$event'])
@HostListener('canplaythrough', ['$event'])
@AlexAegis
AlexAegis / with-teardown.operator.ts
Last active November 28, 2019 14:13
Activate and Teardown side-effect OperatorFunction for RxJS
import { of, OperatorFunction, Observable, EMPTY, merge, NEVER } from 'rxjs';
import { switchMap, finalize, tap } from 'rxjs/operators';
/**
* Sideffect that can tear down the previous object when a new one enters. Can handle undefined and still
* do the teardown on the last element
*
* Neither function will ever recieve undefined values.
*
* Example:
@AlexAegis
AlexAegis / tween-map.operator.ts
Last active April 28, 2019 04:37
Tween mapper for RxJS
import { Observable, OperatorFunction, BehaviorSubject } from 'rxjs';
import { mergeMap, filter } from 'rxjs/operators';
import { Tween, Easing } from '@tweenjs/tween.js';
export interface Tweenable<T> {
from: T;
to: T;
}
@AlexAegis
AlexAegis / finite-progress.operator.ts
Last active June 21, 2022 07:49
RxJS Loading and progress tracking pipeline operator with finite sources!
import { Observable, OperatorFunction } from 'rxjs';
import { tap, map, flatMap, mergeScan, reduce, finalize } from 'rxjs/operators';
/**
* This loader-manager pipeline should be attached to an observable that contains
* a finite amount of observables (preferrably using an of(), like here.)
*
* Loading starts when the source completes!
*
* These observables should be expected to complete, as the pipeline will
@AlexAegis
AlexAegis / infinite-progress.operator.ts
Last active November 28, 2019 14:15
RxJS Loading and progress tracking pipeline operator with an arbitrary number of sources that can be extended anytime!
import { of, Subject, Observable, OperatorFunction } from 'rxjs';
import { delay, tap, map, flatMap, mergeScan, reduce, finalize } from 'rxjs/operators';
/**
* Over-time loader. This pipeline can be attached to a non-ending observable, though, you can't rely
* on the `finalize()` operator for checking if the loading is done or not.
* The observables you supply into it should be completeable.
*
* This can be extremely useful when you want that each of the 'loader' start as soon as possible, but still keep
* track of the progress. At the last `tap()` you can always see when one loader finishes that how many observables
@AlexAegis
AlexAegis / accumulate.function.ts
Last active April 28, 2019 21:52
Object property accumulator for flattening deltas
/**
* Object state accumulator that ignores undefineds
*
* Example usage:
*
* ```typescript
* const accumulator = {};
*
* const stateA = { a: 'value' };
* const stateB = { a: undefined, b: 'bval' };
@AlexAegis
AlexAegis / base.directive.ts
Last active August 21, 2020 02:05
Angular subscription handler, unsubscribes when the component is destroyed
import { OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
/**
* Adds a subscription object and a default OnDestroy hook to the child component
*
* If ngOnDestroy is is overriden in the child component don't forget to call
* ```typescript
* super.ngOnDestroy();
* ```
@AlexAegis
AlexAegis / http-effect.function.ts
Last active August 21, 2020 09:22
Http effect creator for NgRX
import { Actions, ofType } from '@ngrx/effects';
import { ActionCreator } from '@ngrx/store';
import { TypedAction } from '@ngrx/store/src/models';
import { Observable, of } from 'rxjs';
import { catchError, map, switchMap } from 'rxjs/operators';
/**
* It will automatically strip the actions `type` field away before forwarding it
* to the httpCall. This way no accidental type fields are sent anywhere.
*
@AlexAegis
AlexAegis / binary-tree.ts
Created September 23, 2020 13:14
Inverting a binary tree in one line
export class Node<T> {
public left?: Node<T>;
public right?: Node<T>;
public constructor(public value: T) {}
public invert(): Node<T> {
return ([this.left, this.right] = [this.right?.invert(), this.left?.invert()]) && this;
}
public toString(): string {