Skip to content

Instantly share code, notes, and snippets.

View NarHakobyan's full-sized avatar
🎯
Focusing

Narek Hakobyan NarHakobyan

🎯
Focusing
View GitHub Profile
@NarHakobyan
NarHakobyan / auto-unsubscribe.decorator.ts
Created May 27, 2017 16:59
Auto Unsubscribe decorator for angular
export function AutoUnsubscribe( blackList = [] ) {
return function ( constructor ) {
const original = constructor.prototype.ngOnDestroy;
constructor.prototype.ngOnDestroy = function () {
for ( let prop in this ) {
const property = this[ prop ];
if ( !blackList.includes(prop) ) {
if ( property && ( typeof property.unsubscribe === "function" ) ) {
//How To Compare Object Values
var a = { blah: 1 };
var b = { blah: 1 };
var c = a;
var d = { blah: 2 };
Object.compare = function (obj1, obj2) {
//Loop through properties in object 1
for (var p in obj1) {
//Check property exists on both objects
function addMethod(object, name, fn){
// Save a reference to the old method
var old = object[ name ];
// Overwrite the method with our new one
object[ name ] = function(){
// Check the number of incoming arguments,
// compared to our overloaded function
if ( fn.length == arguments.length )
// If there was a match, run the function
@NarHakobyan
NarHakobyan / Open With WebStorm.bat
Created March 19, 2017 12:15
Open file and directory with WebStorm in Windows
@echo off
SET WebStormPath=C:\Users\narek\AppData\Local\JetBrains\Toolbox\apps\WebStorm\ch-0\171.3780.41\bin\webstorm64.exe
echo Adding file entries
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with WebStorm" /t REG_SZ /v "" /d "Open with WebStorm" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with WebStorm" /t REG_EXPAND_SZ /v "Icon" /d "%WebStormPath%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with WebStorm\command" /t REG_SZ /v "" /d "%WebStormPath% \"%%1\"" /f
echo Adding folder entries
function Personal(name, age, gender, occupation, hobby) {
Person.call(this, name, age, gender);
this.occupation = occupation;
this.hobby = hobby;
}
Personal.prototype = Object.create(Person.prototype);
Personal.prototype.constructor = Personal;
Personal.prototype.incrementAge = function () {
Person.prototype.incrementAge.call(this);
import {Directive, Output, EventEmitter, ElementRef} from '@angular/core';
import {Observable, Subscription} from "rxjs";
@Directive({
selector: '[appClickOut]'
})
export class ClickOutDirective {
private listening: boolean;
private globalClick: Subscription;
@NarHakobyan
NarHakobyan / passwordValidation.ts
Created February 23, 2017 18:23
password validator
import {AbstractControl} from '@angular/forms';
export class PasswordValidation {
static MatchPassword(AC: AbstractControl) {
let password = AC.get('password').value; // to get value in input tag
let confirmPassword = AC.get('confirmPassword').value; // to get value in input tag
if(password != confirmPassword) {
console.log('false');
AC.get('confirmPassword').setErrors( {MatchPassword: true} )
} else {
'use strict';
var os = require('os');
var ifaces = os.networkInterfaces();
Object.keys(ifaces).forEach(function (ifname) {
var alias = 0;
ifaces[ifname].forEach(function (iface) {
if ('IPv4' !== iface.family || iface.internal !== false) {