Skip to content

Instantly share code, notes, and snippets.

View narainsagar's full-sized avatar
👋
email me for projects or relocation roles!!

Narain M. narainsagar

👋
email me for projects or relocation roles!!
View GitHub Profile
@narainsagar
narainsagar / angular2-password-matching.md
Created November 15, 2016 13:12
solution for the password/confirm password matching.

solution for the password/confirm password matching:

matchingPasswords(passwordKey: string, passwordConfirmationKey: string) {
    return (group: FormGroup) => {
      let passwordInput = group.controls[passwordKey];
      let passwordConfirmationInput = group.controls[passwordConfirmationKey];
      if (passwordInput.value !== passwordConfirmationInput.value) {
        return passwordConfirmationInput.setErrors({passwordMismatch: true});
 }
@narainsagar
narainsagar / regex.md
Last active October 28, 2016 09:48
Sample Regular Expressions

Whole Numbers

Regex to validate all whole numbers only i..e, [0, 1, 2, 3, ....].

(0|[1-9][0-9]*)

Natural Numbers

Regex to validate all natural (psoitive whole) numbers i..e, [1, 2, 3, ....] sometimes 0 as well.

including zero (0): (0|[1-9][0-9]*)

@narainsagar
narainsagar / unix-current-time.md
Created October 5, 2016 17:14
javascript to convert and get unix (epoch / posix) timestamp.
@narainsagar
narainsagar / nodejs - get filesize in readable format.md
Last active January 14, 2022 05:33
node.js - function to get file and convert the file size in humanly readable format.

node.js - get the filesize in human readable format.

This will take filePath as a function parameter and reads the file via fs module and get the file and converts it's size into more humanly readable format.

const fs = require('fs');
function getFileSize(filename) {
  const stats = fs.statSync(filename);
  //console.log('stats', stats);
 const {size} = stats;
@narainsagar
narainsagar / MyDevTools.md
Last active September 25, 2016 00:48
For MAC (OSX) - App Developer Tools Setup and Installation Guide.

Dev Tools Setup and Installation Guide

$ brew install phantomjs
$ brew install mongodb
@narainsagar
narainsagar / git-commands.md
Last active January 19, 2017 21:41
Git Quick, Useful & Easy Commands.

git useful commands

files to ignore tracking

.gitignore

an empty directory needs a file for git to keep track, convention way is to create a ".gitkeep" file

.gitkeep
@narainsagar
narainsagar / angular-cli install & upgrade instructions
Last active January 7, 2019 13:12
Install or Upgrade [angular-cli](https://github.com/angular/angular-cli) module on your machine instructions / commands.
[angular-cli](https://github.com/angular/angular-cli) installation & upgrade instructions (commands):
# Install (i.e., as a first time?)
```
$ npm install -g @angular/cli@latest
```
# Upgrade to Latest Release
```
$ npm uninstall -g angular-cli @angular/cli
If you haven't already installed npm, or you'd like the latest version:
Check:
```
$ node --version
$ npm --version
```
If both node and npm are not installed then I would recommend you to Install via setup (manually). [Download the latest setup from NodeJS website](https://nodejs.org/en/download/)
@narainsagar
narainsagar / makeFolderTree.js
Last active May 24, 2016 18:13
sample data parsed as directory structure.
/*
// Here is format of data passed to function..
var sampleData = [ '/Users/narain/Sites/todos-task/.DS_Store',
'/Users/narain/Sites/todos-task/.ftppass',
'/Users/narain/Sites/todos-task/.gitignore',
'/Users/narain/Sites/todos-task/Gruntfile.js',
'/Users/narain/Sites/todos-task/LICENSE',
'/Users/narain/Sites/todos-task/README.md',
'/Users/narain/Sites/todos-task/css/.DS_Store',
'/Users/narain/Sites/todos-task/css/normalize.css',