Skip to content

Instantly share code, notes, and snippets.

View sankarseran's full-sized avatar

sankaralingam seranthian sankarseran

View GitHub Profile
import { Directive, HostListener, ElementRef, OnInit } from '@angular/core';
@Directive({ selector: '[InputValidator]' })
export class InputValidatorDirective implements OnInit {
el: any;
constructor(private elementRef: ElementRef) {
this.el = this.elementRef.nativeElement;
}
@sankarseran
sankarseran / simpleAgo.pipe.ts
Created March 27, 2018 13:52
This pipe will give a days ago until 7 days, after that it will return date.
import { Pipe, PipeTransform } from '@angular/core';
import utils from '../utils/utils';
@Pipe({
name: 'simpleAgo'
})
export class SimpleAgo implements PipeTransform {
transform(date: string): any {
let time = Number(date);
if ( time < 1000000000000) {
time = time * 1000;
import { Pipe, PipeTransform } from '@angular/core';
import utils from '../utils/utils';
@Pipe({
name: 'simpleAgo'
})
export class DateConvert implements PipeTransform {
transform(date: string): any {
// console.log('date in the pipe:', date);
let time = Number(date);
if ( time < 1000000000000) {
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'convert'
})
export class HoursToMin implements PipeTransform {
transform(value: string): any {
const d = Number(value || 0) * 3600;
const h = Math.floor(d / 3600);
const m = Math.floor(d % 3600 / 60);
ISODateString(d) {
function pad(n) { return n < 10 ? '0' + n : n }
return d.getUTCFullYear() + '-'
+ pad(d.getUTCMonth() + 1) + '-'
+ pad(d.getUTCDate()) + 'T'
+ pad(d.getUTCHours()) + ':'
+ pad(d.getUTCMinutes()) + ':'
+ pad(d.getUTCSeconds()) + 'Z';
}
import {Directive, ElementRef, HostListener, Input} from '@angular/core';
@Directive({
selector: '[onlyNumber]'
})
export class OnlyNumberDirective {
@Input()
onlyNumber: boolean;
import { Directive, HostListener, HostBinding, EventEmitter, Output, Input } from '@angular/core';
@Directive({
selector: '[appDragAndDrop]'
})
export class DragAndDropDirective {
@Input() private allowed_extensions: Array<string> = [];
@Output() private filesChangeEmiter: EventEmitter<File[]> = new EventEmitter();
@Output() private filesInvalidEmiter: EventEmitter<File[]> = new EventEmitter();
@HostBinding('style.background') private background = '#eee';
import { EventEmitter, ElementRef, OnInit, Directive, Input, Output } from '@angular/core';
import { Observable } from 'rxjs';
import { NgModel } from '@angular/forms';
@Directive({ selector: '[debounce]' })
export class DebounceDirective implements OnInit {
@Input() delay: number = 700;
@Output() keyUpFunc: EventEmitter<any> = new EventEmitter();
constructor(private elementRef: ElementRef, private model: NgModel) {
@sankarseran
sankarseran / child.component.ts
Created September 17, 2018 11:05
This spinet for loading the component, While the route path is changed but the component is not rendered.
import { ErrorHandler, Injectable, Injector, NgZone } from '@angular/core';
import { Router } from '@angular/router';
@Injectable()
export class AppErrorHandler implements ErrorHandler {
constructor(private injector: Injector) { }
handleError(error: any): void {
const routerService = this.injector.get(Router);
@sankarseran
sankarseran / temporary-email-address-domains
Created September 21, 2018 12:36 — forked from adamloving/temporary-email-address-domains
A list of domains for disposable and temporary email addresses. Useful for filtering your email list to increase open rates (sending email to these domains likely will not be opened).
0-mail.com
0815.ru
0clickemail.com
0wnd.net
0wnd.org
10minutemail.com
20minutemail.com
2prong.com
30minutemail.com
3d-painting.com