Autocompile Protobuf Files

Prerequisites:

Add the plugin,

addSbtPlugin(“com.github.gseitz” % “sbt-protobuf” % “0.6.3”)

to the plugins.sbt under the project[root-build] directory.

Add the following libraries to the build.sbt in the library dependencies: “com.google.protobuf” % “protobuf-java” % (version in ProtobufConfig).value % ProtobufConfig.name, and

“com.googlecode.protobuf-java-format” % “protobuf-java-format” % “1.4”

Next add the following statements out side the library dependencies:

—- Changing the default generated source directory location from ‘src_managed’ in ‘target’ to ‘generated-source’ under ‘app’ directory —-

javaSource in ProtobufConfig := baseDirectory.value / “app” / “generated-source”

— Enable the Protobuf Plugin using the below statement–

enablePlugins(ProtobufPlugin)

Note: Make sure the name of the folder residing *.proto files is ‘protobuf’, since it is the default name to identify the *.proto files location to compile & generate protobuf classes. Finally run the `sbt shell` or `SBTConsole` to clean & compile in order to generate the protobuf classes in “generated-source” directory.

NOTE: Any changes made to the build.sbt file will not take effect until we kill the current process in `sbt shell` or `SBTConsole` & start a new one again.

Replacing proto path using REGEX

Replacing proto path using REGEX

Find & replace “import paths” in .proto files:

The following command will replace the text ‘enums/’ to ‘enums’ removing the forward slash in the entire directory consisting of .proto files.

NOTE: Make sure to give the complete text while searching to replace appropriately at the desired locations.

find ./ -name \*.proto -exec sed -i “s;enums/;\\enums;g” {} \;

s;enums/;\\enums;g

The text ‘enums/’ is the text to find in the proto files & the ‘enums’ text after the double back slash is the one to be replaced.

Git working with branches

List all branches:

git branch -a

Create a local branch

git checkout -b dc-server-modification

switch to master after creating branch

git checkout master

switch to branch

git checkout dc-server-modification

Create a remote branch under origin/master

git branch -t dc-server-modification origin/master

Checkout locally remote branch

git checkout -b dc-server-modification

Push to remote branch

How do you merge your changes performed on the branch with the master, while you are there on the branch?
git branch -a : “check the branch on which you are on”
git checkout dc-server-bug-fixes : “checkout the branch”
//Make changes
git add -A && git commit -m “bug fixes”
git status : “check up to date”
git rebase master : Rebase on master happens
git checkout master
git merge dc-server-bug-fixes: “merges all changes master”
git push -u origin master

The following steps might help anyone who are new to git rebase and wanted to do it without hassle

Step 1: Assuming that there are no commits and changes to be made on YourBranch at this point. We are visiting YourBranch.

git checkout YourBranch
git pull –rebase
What happened? Pulls all changes made by other developers working on your branch and rebases your changes on top of it.

Step 2: Resolve any conflicts that presents.

Step 3:

git checkout master
git pull –rebase
What happened? Pulls all the latest changes from master and rebases master on latest master.

Step 4: Resolve any conflicts that presents.

Step 5:

git checkout YourBranch
git rebase master
What happened? Rebase on master happens

Step 6: Resolve any conflicts, if there are conflicts. Use git rebase –continue to continue rebase after adding the resolved conflicts. At any time you can use git rebase –abort to abort the rebase.

Step 7:

git push –force-with-lease
What happened? Pushing changes to your remote YourBranch. –force-with-lease will make sure whether there are any other incoming changes for YourBranch from other developers while you rebasing. This is super useful rather than force push. In case any incoming changes then fetch them to update your local YourBranch before pushing changes.

Why do I need to push changes? To rewrite the commit message in remote YourBranch after proper rebase or If there are any conflicts resolved? Then you need to push the changes you resolved in local repo to the remote repo of YourBranch

Yahoooo…! You are succesfully done with rebasing.

You might also be looking into doing:

git checkout master
git merge YourBranch : “merges the branch with your master”
git push -u origin master : “pushes to master”

Setting up MYSQL in CENTOS 6.9 Command Line

Prerequisite:

Whilst using MYSQL SERVER 5.7 or above kindly ensure to comment the line

#thread_concurrency = 8

 in the file (“/etc/my.cnf “  or “/etc/mysqld/my.cnf “ ) as its deprecated from version 5.7.

Installation Commands:

yum remove mysql57-community-release.noarch
yum clean all
yum install https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
yum install mysql-community-server

Now Start the Server using the following commands:

/etc/init.d/mysql start ## use restart after update

## OR ##

service mysql start ## use restart after update

chkconfig –levels 235 mysqld on

service mysql status

Note: IF service doesn’t start check logs for error using command ‘cat /var/logs/mysqld.log’, if table is damaged kindly run commands to fix

            /etc/init.d/mysqld start –skip-grant-tables && mysql_upgrade

            ## OR ##

            service mysqld start –skip-grant-tables && mysql_upgrade

        /etc/init.d/mysqld status

          ## OR ##

         service mysql status

If the UserName & Password for the server already exists then use command,

            mysql -u root -p

and enter the password to login.

If it’s a first time installation then use the following command to generate “temporary password” to login,

            sudo grep “temporary password” /var/log/mysqld.log

Example Output:

[Note] A temporary password is generated for root@localhost: -et)QoL4MLid

 

Next Follow the steps below to set up the server database (Optional):

 MySQL Secure Installation

  • Change root password
  • Remove anonymous users
  • Disallow root login remotely
  • Remove test database and access to it
  • Reload privilege tables

Start MySQL Secure Installation with following command

/usr/bin/mysql_secure_installation

Output:

Securing the MySQL server deployment.

Enter password for user root:

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:

VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8

MEDIUM Length >= 8, numeric, mixed case, and special characters

STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0

Using existing password for root.

Estimated strength of the password: 100

Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

Estimated strength of the password: 50

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Success.

Normally, root should only be allowed to connect from

‘localhost’. This ensures that someone cannot guess at

the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

Success.

By default, MySQL comes with a database named ‘test’ that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

 – Dropping test database…

Success.

 – Removing privileges on test database…

Success.

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Success.

All done!

Note: If you don’t want some reason, do a “MySQL Secure Installation” then at least it’s very important to change the root user’s password

mysqladmin -u root password [your_password_here]

## Example ##

mysqladmin -u root password myownsecrectpass

  1. Connect to MySQL database (localhost) with password

mysql -u root -p

## OR ##

mysql -h localhost -u root -p

  1. Create Database, Create MySQL User and Enable Remote Connections to MySQL Database

This example uses following parameters:

  • DB_NAME = webdb
  • USER_NAME = webdb_user
  • REMOTE_IP = 10.0.15.25
  • PASSWORD = password123
  • PERMISSIONS = ALL

## CREATE DATABASE ##

mysql> CREATE DATABASE webdb;

## CREATE USER ##

mysql> CREATE USER ‘webdb_user’@’10.0.15.25’ IDENTIFIED BY ‘password123’;

## GRANT PERMISSIONS ##

mysql> GRANT ALL ON webdb.* TO ‘webdb_user’@’10.0.15.25’;

##  FLUSH PRIVILEGES, Tell the server to reload the grant tables  ##

mysql> FLUSH PRIVILEGES;

GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘Root@123’ WITH GRANT OPTION;

 

Guice Dependency Injection

Examples

https://dzone.com/articles/about-dependency-injection

https://www.tgunkel.de/wiki/IT/Guice

Assisted Annotation

https://dzone.com/articles/advanced-dependency-injection

https://groups.google.com/forum/#!topic/google-guice/di5T1JthGPE

The 92% chunk asset optimisation problem nodejs Angular5

At times running Angular Application on an environment which is fresh can be daunting. We may end up with errors which are not in alignment towards the development. One such of a case is the 92% chunk asset optimization problem when running a build of the Angular application.

On AWS hooked up an ec2-instance with Ubuntu 16.04, every thing works fine until you run the command npm run build.

We are stuck in an exception, 92% chunk asset optimisation and the dist directory is not created. Though we end up looking information on the development stack, but at times it could also be related to the Operating System SWAP space.

If the SWAP space on the OS if short or not available, this error shows up and to go around the error follow the instructions to check and allocate swap space on ubuntu. Hopefully this should help in getting around the problem.

One of the easiest way of increasing the responsiveness of your server and guarding against out of memory errors in your applications is to add some swap space. Swap is an area on a hard drive that has been designated as a place where the operating system can temporarily store data that it can no longer hold in RAM.

Basically, this gives you the ability to increase the amount of information that your server can keep in its working “memory”, with some caveats. The space on the hard drive will be used mainly when space in RAM is no longer sufficient for data.

The information written to disk will be slower than information kept in RAM, but the operating system will prefer to keep running application data in memory and use swap for the older data. Overall, having swap space as a fall back for when your system’s RAM is depleted is a good safety net.

sudo swapon -s

Another command for the same thing

free -m

Before we do this, we should be aware of our current disk usage. We can get this information by typing:

df -h

Although there are many opinions about the appropriate size of a swap space, it really depends on your personal preferences and your application requirements. Generally, an amount equal to or double the amount of RAM on your system is a good starting point.

Since my system has 4 Gigabytes of RAM, and doubling that would take a significant chunk of my disk space that I’m not willing to part with, I will create a swap space of 4 Gigabytes to match my system’s RAM.

Creating SWAP File
sudo fallocate -l 4G /swapfile
Check by running the following command that the SWAP file was created and space was reserved
ls -lh /swapfile
Enable SWAP Fiile
sudo mkswap /swapfile
Verfiy Permissions are set correctly
ls -lh /swapfile
Now that our file is more secure, we can tell our system to set up the swap space by typing:
sudo swapon /swapfile

We can verify that the procedure was successful by checking whether our system reports swap space now:

sudo swapon -s
Filename                Type        Size    Used    Priority
/swapfile               file        4194300 0       -1

We have a new swap file here. We can use the free utility again to corroborate our findings:

free -m

https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

———————Setting up Angular Environment Using NVM———————-

Requirements:
1.nodejs.
2.@angular/cli.

Procedure:
1.Install NVM (Node Version Manager):
By far the easiest way to install node.
run commad :
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash

-This installs NVM, use command ‘nvm -v’ to check if it is installed.

Note: Re-open Terminal after install ‘nvm'(if ‘nvm -v’ doesn’t work).

2.run command:
nvm install node

-This installs the latest version of node

To install a specific version of node use:
nvm install <version>
ex:
nvm install 6.11.5
(Installs version 6.11.5)

3.Install Angular CLI(Command Line Interface)
run:
npm install -g @angular/cli

To check run:
ng

Install pm2 (For running on Server. Skip this step if you are doing local setup):

npm install pm2 -g

—–AND YOU ARE GOOD TO GO

My HandBook on Angular

1) install Angular CLI: npm install -g @angular/cli
    [Note:Sometimes forms and http packages will not be installed inorder to do so, run the following commands:
    a) npm install -g forms/npm install forms(for installing forms package in node_module).
    b) npm install -g http/npm install http(for installing http package in node_module).
        -g stands for global, which simply means global installation.]
2) Create New Application: ng new project-name/application-name[Ex:angular-tour-of-heroes]
     (Note: The name of the project must not have white space, instead use – )
3) Serve the application/Run the Application:
    Go to the project directory and launch the application.
    cd project-name/application-name[Ex:angular-tour-of-heroes]
    ng serve – – open/-o[To open/run the Project/Application]
    (Note:The ng serve command builds the app, starts the development server, watches the source files, and rebuilds        the app as you make changes to those files.
    The – – open flag opens a browser to http://localhost:4200/)
4) Change the application title:
    Open the project in your favourite editor or IDE and navigate to the src/app folder.
    You’ll find the implementation of the shell AppComponent distributed over three files:
    app.component.ts— the component class code, written in TypeScript.
    app.component.html— the component template, written in HTML.
    app.component.css— the component’s private CSS styles.
5) Creating Components:
    ng generate component [component-name] / ng g c [component-name]
    ng generate component /sub-folder1/2/…/[component-name]
    Creating a component without a spec file:
    ng generate component [component-name] – – spec=false / ng g c [component-name] – – spec=false
          (OR)
    ng generate component [component-name] – – spec false / ng g c [component-name] – – spec false.
    Creating a component without a spec file, and without being imported  in app.module.ts:
    ng generate component [component-name] – – spec=false / ng g c [component-name] – – spec=false – – skip-import
          (OR)
   ng generate component [component-name] – – spec false / ng g c [component-name] – – spec false – – skip-import
6) Command prompt:
    a)open: Ctrl + ~
    b) close: Ctrl + C
    c) clear
7) To change the port of execution: ng serve -p [portnumber]
    (Ex: ng serve -p 3000)
    (note: give any port number, default port-number is:4200)
     To host and execute:
     ng serve – – host 0.0.0.0 – – open (OR)
     ng serve -h 0.0.0.0 -o (to run on default port)
     ng serve -h 0.0.0.0 -p 3000 -o(to run on user defined port)
8) For statement:The syntax is *ngFor=”let <value> of <collection>”.
     [Ex: *ngFor=”let hero of heroes”]
9)  Creating Services: ng generate service [service-name] / ng g s [service-name]
     (Ex: ng generate service hero)
10) Providing the service(i.e regestering service into app.module.ts):
      ng generate service [service-name] – – module=app / ng g s [service-name] – – module=app
     (Ex: ng generate service hero – – module=app)
11) Creating and providing service:
      ng generate service [service-name] – – module=app / ng g s [service-name] – – module=app
      (Ex: ng generate service hero – – module=app)
12) Creating Routing and adding it to the app.module.ts:
       ng generate module [routonFetchData()ing-page-name] – – flat – – module=app
       (Ex: ng generate module app-routing – – flat – – module=app)
       [Note:- – flat puts the file in src/app instead of it’s own folder.
       – – module=app tells the CLI to register it in the imports array of the AppModule.]
       A typical Angular Route has two properties:
       path: a string that matches the URL in the browser address bar.
       component: the component that the router should create when navigating to this route.
13) Install the In-Memory Web API package from npm:
       npm install angular-in-memory-web-api – – save
14) Note:
      If you neglect to subscribe(), the service will not send the delete request to the server!
      As a rule, an Observable does nothing until something subscribes!
      Confirm this for yourself by temporarily removing the subscribe(),
      clicking “Dashboard”,  then clicking “Heroes”. You’ll see the full list of heroes again.
      AsyncPipe
      As expected, the *ngFor repeats hero objects.
      Look closely and you’ll see that the *ngMatPaginatorFor iterates over a list called heroes$, not heroes.
      <li *ngFor=”let hero of heroes$ | async” >
      here, hero is a temporary variable, which must be declared with the help of the keyword  “let”.
      “of” is a keyword used to iterate through a specified set of values.
       heroes is the one consisting of a set of values.
       The $ is a convention that indicates heroes$ is an Observable, not an array
       The *ngFor can’t do anything with an Observable.
       But, there’s also a pipe character ( | ) followed by async, which identifies Angular’s AsyncPipe.
       The AsyncPipe subscribes to an Observable automatically so you won’t have to do so in the component class.
14) Installing Bootstrap: npm install – – save bootstrap/npm install – – save bootstrap@3
      {Note: in installing bootstrap@3, the notation @3 refers to installing of bootstrap version 3]
15) Using Bootstrap in our project after installation:
      goto project explorer->open project->src->{}.angular-cli.json->”styles”: ->
      then give the reference of bootstrap file as follows:
       “../node_modules/bootstrap/dist/css/bootstrap.min.css”
       Example:
       “styles”: [
       “../node_modules/bootstrap/dist/css/bootstrap.min.css”,
       “styles.css”
       ],
16) Using ng Model:
      Angular $ does’nt have the default library in order to load ng Model in order to do so,
      we must import the following library in AppModule.ts.
     AppModule.ts:
     import {FormsModule} from ‘@angular/forms’ and in imports section of @NgModule add  FormsModule.
     Declaration of ngModel in html page: <input type=”text” [(ngModel)]=”name”>
      [Note:in order to give dynamic value to the ngModel type, declare it in .ts file as [ngModel – name]=[‘ ‘]
      (Ex: name=’ ‘)]
      [Note2: the input tag designated with a void value must not be have a closing tag.
      Ex:<input type=”text” [(ngModel)]=”name”>
      in the above example the input tag is not assigned a value, hence it has a void value,
      Therefore, it must not have a closing tag.]
16) Plugins recommended: emmet
17) important imports to be added to app.module.ts:
      import { NgModule } from ‘@angular/core’;
      import { BrowserModule } from ‘@angular/platform-browser’;
      import{FormsModule} from ‘@angular/forms’;
      import{HttpModule} from ‘@angular/http’;
      under @NgModule in imports section:
      imports: [
      BrowserModule,
      FormsModule,
      HttpModule
      ],
18) if-statement syntax: *ngIf [Note:must use * as a prefix to ngIf, * is used since it is structural.
     *ngIf must be used the attributes like <p> tag]
      Ex:<p *ngIf=”ServerCreated”>Server was created, server name is {{ServerName}}</p>
19) Install Angular Augury extention to chrome for a a better debugging experience.
20) Simplified declarations using Constructors:
      Before:
          ex:ingredient.model.ts :-
               export class Ingredient {
               public name: string;
               public amount: number;
               constructor(name: string, amount: number) {
               this.name = name;
               this.amount = amount;
              }
           }
       After:
         ex:ingredient.model.ts :-
              export class Ingredient {
              constructor(public name: string, public amount: number) {
              }
            }
21) Lifecycle of Components:
   a) ngOnChanges: Called after a boundinput property changes.
   b) ngOnInit: Called once the component is initialized.
   c) ngDoCheck: Called during every change detection run.
   d) ngAfterContentInit: Called after content(ng-content) has been projected into view.
   e) ngAfterContentChecked: Called every time the projected content has been checked.
   f) ngAfterViewInit: Called after the component’s view (and child views) has been itialized.
   g) ngAfterViewChecked: Called every time the view (and child views) has been checked.
   h) ngOnDestroy: Called once the component is about to be destroyed.
22) Creating a Directive: ng generate directive [directive-name] / ng g d [directive-name]
      Ex: ng g d my-directive
23) if compile on save of visual studio does not work try these command:
       ng set – – global warnings.versionMismatch=false
                                              (OR)
       The problem may be related with Inotify Watches Limit on Linux.
       To solve to issue increase the watches limit to 512K
       sudo sysctl fs.inotify.max_user_watches=524288
       sudo sysctl -p – – system
24) Kill a program currently running in port 4200 commands:
       sudo kill $(sudo lsof -t -i:4200)
                        (OR)
       sudo kill `sudo lsof -t -i:4200`
25) Installing angular material complete guide:
       https://alligator.io/angular/angular-material-2/
26) Example for various angular material controls:
       https://stackblitz.com/edit/angular-material2-formgroup-issue?                                                 file=app%2Fapp.component.html
26) Installing firebase SDK:
       npm install – – save firebase
       Once installation is done goto appComponent.ts, then go to ngOnInit method,
       and then type the following code:
          ngOnInit() {
          firebase.initializeApp({
          apiKey: “AIzaSyCodykBIemB9N2FOn7PU93OIoRc1CB3SNY”,
          authDomain: “ng-recipe-book-505417.firebaseapp.com”,
        });
      }
     Note: the apiKey and authDomain veries for every user in order to get your own goto
               firebase console, then click on Authentication tab located on the left hand side,
               then in the authentication page click on web setup tab,
               then copy apiKey and authDomain.
27) Installing MySQL WorkBench:

28) Upload your csv file to a location and get the csv file data. Please try this:-

Component.html:-

<input type="file" class="upload" (change)="changeListener($event.target.files)">

Component.ts:-

public changeListener(files: FileList){
  console.log(files);
  if(files && files.length > 0) {
     let file : File = files.item(0); 
       console.log(file.name);
       console.log(file.size);
       console.log(file.type);
       let reader: FileReader = new FileReader();
       reader.readAsText(file);
       reader.onload = (e) => {
          let csv: string = reader.result;
          console.log(csv);
       }
    }
}

29)ng serve –host 0.0.0.0 -p 4200

30)running on pm2:

a) first run npm run build i.e npm i && npm run clean && ng build –prod(builds the project and creates a dist folder)

b) pm2 start datacaptive-scrapes-ui.js(pm2 start js file/ process name, note that in js file we have specified the project to run on port 3000)

c) pm2 list(lists all the process that are running)

d) pm2 stop datacaptive-scrapes-ui.js(pm2 stop js file/process name)

e) pm2 delete datacaptive-scrapes-ui(note it does not have the js extension, this command is used to delete the process)

git fails with command: Failed to connect to xxx-xxx-xx-xx port xxxx: Connection refused

 

user@Sys154:~/projects/hipl$ git clone https://gitlab.com/test/test-server.git
Cloning into ‘test-server’…
fatal: unable to access ‘https://gitlab.com/test/test-server.git/’: Failed to connect to 163.172.110.218 port 2465: Connection refused

This happens because a proxy is configured in git.

Since it’s https proxy (and not http) git config http.proxy and git config --global http.proxy can’t help.

1 : take a look at your git configuration

git config --global -l

If you have nothing related to https proxy like https_proxy=... the problem is not here.

If you have something related to https proxy then remove it from the file ~/.gitconfig and try again

2 : if it still doesn’t work, unset environment variables

Check your environment variables :

env|grep -i proxy  

You should have one or several lines with https_proxy=...

Unset one by one with : unset https_proxy (or HTTPS_PROXY depending of the name of the variable)

3 : check environment variables again

env|grep -i proxy

If it shows nothing you should be good.

Note : This solution can applies to http and https proxy problems. just the variables name changes from https to http