Skip to content

Instantly share code, notes, and snippets.

View kaplan81's full-sized avatar
💭
Learning GraphQL

Andres Gesteira kaplan81

💭
Learning GraphQL
  • Berlin. Germany.
View GitHub Profile
@kaplan81
kaplan81 / fibonacci.js
Last active January 10, 2016 17:56
Fibonacci Series
function fibonacci(size) {
var result = [0];
var counter;
for (counter = 1; counter < size; counter++) {
result[counter] = (result[counter-1] || 1) + result[Math.max(0, counter-2)];
}
return result;
}
// fibonacci(8) returns [ 0, 1, 1, 2, 3, 5, 8, 13 ]
@kaplan81
kaplan81 / bubbling.html
Created January 11, 2016 22:33
Bubbling Example
<!DOCTYPE html>
<html>
<head>
<title>Bubbling Example</title>
<style>
.div-style {
display: table-cell;
padding: 20px;
text-align: center;
@kaplan81
kaplan81 / _testing.md
Last active August 8, 2022 19:27
Angular unit test helpers and samples

Testing

Helpers and examples for unit testing on Angular applications and libraries.

import { NavigationExtras, Params } from '@angular/router';
export interface NavRoute<P> {
path: ['/', ...P[]];
query?: Params;
extras?: NavigationExtras;
callback?: (value?: any) => any;
}
export interface NavLink<P> extends NavRoute<P> {
import { Location } from '@angular/common';
import { Injectable } from '@angular/core';
import { NavigationExtras, Router } from '@angular/router';
import * as fromRootModels from '@first-app/models';
import * as routerActions from '@first-app/store/actions/router.action';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { map, tap } from 'rxjs/operators';
@Injectable()
export class RouterEffects {
export enum NavBase {
empty = '',
root = '/',
wildcard = '**'
}
export enum NavPath {
path1 = 'path1',
path2 = 'path2',
path3 = 'path3'
import { OnDestroy } from '@angular/core';
import { Subject } from 'rxjs';
export abstract class SubscribedContainer implements OnDestroy {
destroyed$ = new Subject<void>();
/**
* DO NOT this.destroyed$.complete();
* It is not necessary:
* https://stackoverflow.com/questions/44289859/do-i-need-to-complete-a-subject-for-it-to-be-garbage-collected
*/
import { Component, OnInit } from '@angular/core';
import { interval, Observable } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { subscribedContainerMixin } from '@my-scope/my-ng-lib/subscribed-container.mixin';
@Component({
selector: 'subscribed-container',
templateUrl: './subscribed-container.component.html'
})
export class SubscribedContainerComponent extends subscribedContainerMixin() implements OnInit {
import { OnDestroy } from '@angular/core';
import { Constructor } from '@my-scope/my-ng-lib/constructor';
import { Subject } from 'rxjs';
// WARNING: THIS DOES NOT WORK IN ANGULAR 8 WITH AOT!
// HOWEVER, IT DOES WORK IN ANGULAR 9!
/**
* Mixin class to automatically unsubscribe in component classes.
*
import { DebugElement } from '@angular/core';
import { ComponentFixture } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
export interface ComponentSuiteElements<H, N = any> {
host: ComponentTestingElement<H>;
nested?: ComponentTestingElement<N>;
}
export interface ComponentTestingElement<T> {