Skip to content

Instantly share code, notes, and snippets.

View DazSanchez's full-sized avatar

Hugo Sánchez DazSanchez

  • Blueriver
  • Veracruz, México
  • 19:09 (UTC -06:00)
View GitHub Profile
@DazSanchez
DazSanchez / filter-map.js
Created May 8, 2020 00:56
FilterMap util
// Typescript
type Predicate<T> = (v: T) => boolean;
type Mapper<T, V> = (item: T) => V;
export const createFilterMap = <T, V>(predicate: Predicate<T>, map: Mapper<T, V>) => {
return (values: T[]): V[] => {
return values.reduce((reduced, nextValue) => {
if (predicate(nextValue)) {
return reduced.concat(map(nextValue));
types = {
[TYPES_PRODUCT.COACHING]: 'tv',
[TYPES_PRODUCT.CONSULTING]: 'question_answer',
[TYPES_PRODUCT.CONFERENCE]: 'mic'
}
// ...
transform(type: string) {
return types[type];
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<div class="main">
<div class="item" (inViewport)="startCounters()">
<p counter [to]="10000" [duration]="10">0</p>
<p counter [to]="100" [duration]="20">0</p>
<p counter [to]="19" [duration]="30">0</p>
<p counter [to]="10" [duration]="15">0</p>
</div>
</div>
import { Directive, ElementRef, Output, EventEmitter, OnDestroy } from "@angular/core";
import { fromEvent, Subscription } from "rxjs";
import { filter } from "rxjs/operators";
@Directive({ selector: "[inViewport]" })
export class InViewportDirective implements OnDestroy {
@Output("inViewport") inViewport = new EventEmitter();
private subscription: Subscription;
@DazSanchez
DazSanchez / counter.directive.ts
Last active February 2, 2019 00:56
Counter directive using CountUpJS
import { Directive, ElementRef, EventEmitter, Input, OnInit, Output } from "@angular/core";
import CountUp from "countup.js";
@Directive({
selector: "[counter]",
exportAs: "countUp"
})
export class CounterDirective implements OnInit {
@Input() from: number = 0;
@Input() to: number;