Skip to content

Instantly share code, notes, and snippets.

View isaurssaurav's full-sized avatar
:shipit:
Focusing

Saurav Maharjan isaurssaurav

:shipit:
Focusing
View GitHub Profile
@isaurssaurav
isaurssaurav / socail-share-urls.snippets
Created February 21, 2017 06:08
Socail Share Urls
Creating share buttons with just URL's
Google
https://plus.google.com/share?url=<URL>
E.g. https://plus.google.com/share?url=https%3A%2F%2Fwww.google.com
Twitter
@isaurssaurav
isaurssaurav / linux.upgrade-node-to-latest-version.snippets
Last active March 16, 2017 11:55
upgrade node to latest version/stable
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/node
**for latest version**
sudo n latest
@isaurssaurav
isaurssaurav / replace-prefix-mysql.snippets
Created March 19, 2017 04:31
//only valid in phpmyadmin
In phpmyadmin select all tables of your database.
From the dropdown 'With selected:' choose 'Replace table prefix'
Set from->to replacement.
DONE
@isaurssaurav
isaurssaurav / yii2-custom-validation.php
Created March 21, 2017 11:02
custom validation yii2
public function rules()
{
return [
// username and password are both required
[['password','username'], 'required'],
[['username'],'validateUsername'],
// rememberMe must be a boolean value
//['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword', 'skipOnError' => false],
@isaurssaurav
isaurssaurav / linux.where-is-network-share-folder-in-ubuntu-linux.snippets
Last active March 21, 2017 11:03
where is network share folder in ubuntu linux
/var/run/user/1000/gnvfs
@isaurssaurav
isaurssaurav / angular2.use-of-elementRef-rendrer-custom-directive.ts
Created March 22, 2017 17:14
Angular 2. Use of ElementRef and Renderer plus custom directive
import { Directive ,ElementRef, Renderer } from '@angular/core';
@Directive({
selector: '[highlight]', //element having hightlight [attribute] is selected or .class or #id or component
})
export class HighlightDirective {
constructor(private elementRef: ElementRef,private renderer:Renderer) {
// this.elementRef.nativeElement.style.color = 'red';
this.renderer.setElementStyle(this.elementRef.nativeElement,'background-color','red');
}
@isaurssaurav
isaurssaurav / angular2.host-binding-listener.ts
Last active March 22, 2017 17:25
angular2.HostBinding and HostListener example
import { Directive ,HostListener,HostBinding } from '@angular/core';
@Directive({
selector: '[highlight]', //element having hightlight [attribute] is selected or .class or #id or component
})
export class HighlightDirective {
@HostListener('mouseenter') mouseover(){
this.backgroundColor = 'green';
//can use renderer here to change style here
}
@isaurssaurav
isaurssaurav / angular.2.custom-directive.snippets
Created March 24, 2017 15:46
custom directive 2.it uses TemplateRef ViewContainerRef
//this directie uses templateref,viewcontainer ref ..and works exact opposit of *ngif
import { Directive, TemplateRef, ViewContainerRef,Input } from '@angular/core';
@Directive({
selector:'[unless]'
})
export class UnlessDirective{
@isaurssaurav
isaurssaurav / angular2.navigate.snippets
Created March 25, 2017 13:20
angular2 navigate from function or code
import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';
@Component({
selector: 'app-user',
template: `<h1>user component</h1>
<a [routerLink]="['']">Home</a>
<button (click)="onNavigate()">Go Home</button>
@isaurssaurav
isaurssaurav / angular2.getparam.snippets
Created March 25, 2017 15:01
angular2 get a param in component
import { Component, OnInit, OnDestroy } from '@angular/core';
import {Router,ActivatedRoute} from '@angular/router';
import {Subscription} from 'rxjs/Rx';
@Component({
selector: 'component name',
template: `<h1>user component</h1>