Thursday, January 17, 2019

Windows10 Licencing

Licencing is a headache, if you don't do it, even if you paid for licence, you can not use a product. This short article touches the surface of licencing in Windows 10.

View Installed Licence

Yes, to use Windows 10, we need a valid licence. Windows stores this licence somewhere in your system, so that, it normally automatically activates your system and you do not need licence again. Sometimes, this is not enough because we need to manually activate the system and in this situation, we need the actual licence.

Windows hides the licence from viewing(only last 5 letters are shown), that means we need to get the script which shows the installed licence in the system.

I got a working Visual Basic Script which shows the installed licence in the system.

File: GetProductKey.vbs
(script source: https://www.winhelponline.com/blog/view-your-product-key-windows-10-8-7-script/)
Option Explicit  
 
Dim objshell,path,DigitalID, Result  
Set objshell = CreateObject("WScript.Shell") 
'Set registry key path 
Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" 
'Registry key value 
DigitalID = objshell.RegRead(Path & "DigitalProductId") 
Dim ProductName,ProductID,ProductKey,ProductData 
'Get ProductName, ProductID, ProductKey 
ProductName = "Product Name: " & objshell.RegRead(Path & "ProductName") 
ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID") 
ProductKey = "Installed Key: " & ConvertToKey(DigitalID)  
ProductData = ProductName  & vbNewLine & ProductID  & vbNewLine & ProductKey 
'Show messbox if save to a file  
If vbYes = MsgBox(ProductData  & vblf & vblf & "Save to a file?", vbYesNo + vbQuestion, "BackUp Windows Key Information") then 
   Save ProductData  
End If 
 
 
 
'Convert binary to chars 
Function ConvertToKey(Key) 
    Const KeyOffset = 52 
    Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert 
    'Check if OS is Windows 8 
    isWin8 = (Key(66) \ 6) And 1 
    Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4) 
    i = 24 
    Maps = "BCDFGHJKMPQRTVWXY2346789" 
    Do 
           Current= 0 
        j = 14 
        Do 
           Current = Current* 256 
           Current = Key(j + KeyOffset) + Current 
           Key(j + KeyOffset) = (Current \ 24) 
           Current=Current Mod 24 
            j = j -1 
        Loop While j >= 0 
        i = i -1 
        KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput 
        Last = Current 
    Loop While i >= 0  
     
    If (isWin8 = 1) Then 
        keypart1 = Mid(KeyOutput, 2, Last) 
        insert = "N" 
        KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0) 
        If Last = 0 Then KeyOutput = insert & KeyOutput 
    End If     
     
 
    ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5) 
    
     
End Function 
'Save data to a file 
Function Save(Data) 
    Dim fso, fName, txt,objshell,UserName 
    Set objshell = CreateObject("wscript.shell") 
    'Get current user name  
    UserName = objshell.ExpandEnvironmentStrings("%UserName%")  
    'Create a text file on desktop  
    fName = "C:\Users\" & UserName & "\Desktop\WindowsKeyInfo.txt" 
    Set fso = CreateObject("Scripting.FileSystemObject") 
    Set txt = fso.CreateTextFile(fName) 
    txt.Writeline Data 
    txt.Close 
End Function

After saving this content into the file, we can execute the file which shows the installed licence.

 How to Activate Licence (slmgr)

Windows has given us a very useful tool called slmgr.vbs which is used to view licence information and many other licence related operations.

Please have a look at this article for detailed information regarding slmgr tool:

https://www.howtogeek.com/245445/how-to-use-slmgr-to-change-remove-or-extend-your-windows-license/

I have listed some useful commands using slmgr.vbs tool.

a) slmgr.vbs /dli (Display licence information)
b) slmgr.vbs /dlv (Detail licence view)
c) slmgr.vbs /xpr (Expiration date)
d) slmgr.vbs /upk (Uninstall product key) => Restart required.
e) slmgr.vbs /cpky (Clear product key from registry only)
f) slmgr.vbs /ipk ####-####-####-####-#### (Install product key)
g) slmgr.vbs /ato (Activate online)
h) slmgr.vbs /dti (Displays confirmation Id) => this id should be given to support for offline activation, then support gives your activation_id.
g) slmgr.vbs /atp activation_id (Activate with id)




Friday, January 11, 2019

Basic Git commands

1. Cloning a git branch

git clone -b solution https://github.com/SNCodingChallenge/stm_challenge_krishna_paudel.git

2. Change push repository

   First clone the git project into your local:
   git clone git@kpaudel.com.np:/opt/git/MyProject.git
 
 Go into MyProject folder and hen remove the .git folder which clears out all the old information. Run the command:

git init 

Which regenerates git information. Now we add remote repository to push:

  git remote add git@mysansar.com:/repos/git/MyNewProject.git 

Now verify:

  git remote -v 


3. Create a new repository in the server

 Create a folder MyNewProject.git into Server repository.
 Go into the directory and execute

   git init --bare

Give access rights to the git user. (Normally we set the owner of the directory as git)

4. Push to the remote repository

git push origin master

5.Commit changes to the local repository

git commit -m "Message" .

6.Merge updates from a branch

git pull [origin branch]

Example:
a) Merging from the same branch
git pull

b) Merging from master branch
git pull origin master

Note: If sometimes, the pull merging gives the following failure:
"refusing to merge unrelated histories"
Then the following command will be useful.

git pull origin master --allow-unrelated-histories

7. Disable http ssl verification

We need this when we create a certificate by ourselves for our private purpose. In that situation, we have to disable SSL verification or simply use ssh. 


git config --global http.sslverify "false"

8. Store GIT credentials

Sometimes we need this feature if you are tired of providing the username and password while executing the git command. The solution for this is to store credentials,

git config --global credential.helper store

It stores the credential and you never need to provide the username and password.

There are some options too:
git config --global credential.helper 'cache --timeout=600'
git config --global credential.helper cache


10. Display the branch name in the terminal

If we display the branch name in the terminal, it helps us to know which branch we are working on and also prevents mistakenly working on other unintended branches.

I found the script to run to activate this feature in the terminal. 

# Show git branch name
force_color_prompt=yes
color_prompt=yes
parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt

Just save this file in "git-branch-name.sh" in your preferred location and run this at the time the system starts.
To run this script while the system loads, we need to append the following lines in the .bashrc file. 
...
# To display git branch name in the terminal
if [ -f /Backup/scripts/git-branch-name.sh ]; then
   . /Backup/scripts/git-branch-name.sh 
fi 
...

Monday, December 31, 2018

Happy New Year 2019!!!

We are very near (10 minutes) to the new year, I wanna say everybody "Happy New Year 2019". Since this blog is my technical blog, I am gonna write my technical experience. So far I have not written any such new year resolution in a technical field. Today, suddenly, something came up into my mind, why not write new year resolutions and see which are fulfilled after one year.

1) GIT = Thorough Learning
2) Gradle = Thorough Learning
3) NodeJS = Implement RestAPI (with NoSQL DB)
4) NoSQL(MongoDB) (partly from professional project)
5) ReactJS
6) Docker
7) RestAPI (Server & Client) (from professional project)
8) WebSocket Server & Client (Spring & NodeJS) (from professional project)
9) Python(with Tensorflow)
10) Hobby Projects in Arduino & Raspberry PI: Implement above technologies in this projects
11) Jenkins
12)Spring Boot: (from professional project)


The fireworks are becoming louder and louder. Oh, just 2 minutes now. I gotta go to watch fireworks!

I am back and its already 2019! Lets welcome 2019.










Sunday, December 9, 2018

MongoDB Walkthrough

INTRODUCTION

MongoDB is a quite popular no-SQL database system. In this article, I am going to write something about this database system. Yes, no-SQL databases are meant for performance and scalability, however, like relational databases, there exists no relation between tables or collections in the database.

MongoDB is super easy, can be run in a single host, and data is stored in document format(as JSON objects) which makes very easy to analyze or export. It provides a nice client GUI tool called "MongoDB Compass".  The storage of data is transparent in the sense that we can copy the database and reuse it. Also, there are flexibilities regarding the log files, data files, and config files.

I have used another alternative no-SQL database called Cassandra, which is also powerful and popular. Cassandra, however, requires more resources than MongoDB. Also, I could not get any better GUI client tools. Configuration is also a bit different compared to MongoDB. Cassandra is Java-based, MongoDB is C++ based.

INSTALLATION:

There are methods to install:

1) Using Debian file available from

https://repo.mongodb.org/apt/ubuntu/dists/xenial/mongodb-org/4.0/multiverse/binary-amd64/mongodb-org-server_4.0.4_amd64.deb

2) Using Terminal

sudo apt install mongodb-server
sudo apt install mongodb-clients

3) Using installation files from

http://downloads.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-v4.0-latest.tgz

CONFIGURATION

The above mentioned two methods are quite straightforward, do not basically need any configuration.
I am writing the configuration of installation step 3 mentioned above.

# After downloading, extract the file and place contents into /opt/mongodb. Create a short link of the original extracted folder into /etc/mongodb.

# Set /opt/mongodb/bin as PATH variable so that we can directly run MongoDB commands.

# Create a folder /data/db
sudo mkdir -p /data/db

# Start Server

sudo mongod --dbpath /data/db --logpath /var/log/mongodb/mongod.log --fork

or create a config file /etc/mongod.conf with the following contents:

# mongod.conf
systemLog:
 destination: file
 path: "/var/log/mongodb/mongod.log"
 logAppend: true
storage:
 journal:
  enabled: true
processManagement:
 fork: true 
net:
 bindIp: 0.0.0.0
 port: 27017

And run the following command:

sudo mongod -f /etc/mongod.conf


# Stop Server

sudo mongod --shutdown

# Change bind address

The default is localhost can connect to the server, and any connections from outside are blocked. So, we need to change the bind address. 

We change the file /etc/mongod.conf created above step. 

Default is:

net:
  bindIp: 127.0.0.1

Change it to

net:
  bindIp: 0.0.0.0 # allow connections from anywhere

# Configure autostart

Everytime system restarts, the server should also start. We define a cronjob for that(/etc/cron.d/mongodb) with the following content:

@reboot root sleep 60 && /opt/mongodb/bin/mongod -f /etc/mongod.conf

We have defined one minute(60 seconds) sleep before starting mongodb server.

An alternative will be to create a service, and we can enable service to start at the time system starts.

CLIENTS:

1. Command Line Tool: mongo 

We can connect using mongo. Mongo uses default values to connect to the server. There are several options for this command.

After running the command, we go into the environment we can run MongoDB commands to access the database and carry out several dataset related operations.

Sample operations:
a. Connect to remote mongodb server
    mongo --host server[:port]
                           or
    mongo "mongodb://server:port"

b. Select database

  use database

c. Authenticate

    db.auth(user,password)     


2. GUI Administration: MongoDB Compass

This is a nice GUI tool, we can carry out operations on collections and documents using this nice GUI tool.

3. Create a user

Using the mongo command-line tool, we create a user.
use admin
db.createUser(
  {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
  }
)

We have to provide option --auth in mongod command to enable authorization. 

Or add the following line in the /etc/mongod.conf file:

security:

 authorization: enabled

Saturday, December 8, 2018

Path Variable in Ubuntu System


The paths defined in Ubuntu or any operating systems are searched to find out any commands given in command line terminal. If a program is installed from Debian(.deb) or windows installer(.exe), then the installer defined the path automatically. 

If we have not packaged installer, we get all files in a folder with a bin directory inside it with all executables. The bin folder contains executables should be available from the terminal, otherwise, we have to go into the executable location to execute the binary files.

There are two methods we can define path variable in Linux system (Actually, I tested it with Ubuntu 18.04 and 16.04, other Linux systems should also work.)

Method 1: User-specific path variable. 

Each user can define their own path variable. The path to define path variable is 
~/.bashrc

export PATH=/path/to/bin:$PATH

Then the following command makes it effective. 

$ source ~/.bashrc 

Or we can restart the terminal to take effect. 


Method 2: System path variable 

 This method is used to set the path variable globally, that means these path variables are defined systemwide. The path to define the path variable is 

/etc/environment

Just open it as a root user, add the path variable as follows:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/cassandra/bin:/path/to/bin"

Then run the following command to carry out effect:

$. /etc/environment

I hope this is helpful to you guys!

Friday, May 11, 2018

Tweak Ubuntu 18.04 desktop

Ubuntu 18.04 is another long-term upgrade with a lot of changes. I have freshly installed it in my system and it is running very smoothly. To let you know, I have replaced Linux Mint 18 which is also a great operating system.

Ubuntu has made GNOME desktop back, that means, it looks like unity but it is modified GNOME which I really appreciated. (Note: I only install LTS versions, so I have no experience with the short-term versions)

Although it looks really cool with GNOME desktop and I have no comments. Still, for windows or mint users, the left vertical bar looks a bit confusing. So, my first attempt would be to move this vertical bar at the bottom.


Dock Positioning

What basically I did it: I went to settings->Dock where we can define the dock position on the screen. There are three possibilities: LEFT, BOTTOM, RIGHT as shown below:

 
Yes, we can define the icon size also by dragging the range selector. So, basically, I selected the Dock position as bottom and my window looks like this:


Ok, so far so good, it looks like windows or mint system, is really comfortable for me. Did you notice the application's icon is on the right bottom corner? It is okay, for me, I prefer it on the left bottom corner like conventional start icon in windows and applications icon in the mint system.

So, I, now wanted to move this. Is it possible? Yes, because Google knows everything. I found this article:

https://medium.com/@amritanshu16/move-show-applications-button-to-top-of-the-dock-in-ubuntu-17-10-5530beeaeef2

We need to run just the following command:

gsettings set org.gnome.shell.extensions.dash-to-dock show-apps-at-top true

If you don't like commands, just install deconf-tools as follows:

sudo apt install dconf-tools

and then run the program dconf-editor.

Now, everything is as expected.  Look below:



Enjoy GNOME! 

Monday, April 30, 2018

Docker Installation & Configuration

Introduction

Docker is nowadays a buzz word, I heard this everywhere in software development sector. I went through it to learn what it actually it and why do we need it. First of all, before we go into need of docker, we have to know about virtual machines. Yes, docker is kind of virtual machine, but virtual machines are bloated, need more resources. That means we can run many instances of docker compared to virtual machines in the same system.

The lightweight nature of docker instances has several advantages such as more customized configuration, and also application portability. The application can be deployed into docker and can be packed and shipped anywhere.  Because of this, the developers prefer docker to deploy their applications in a cloud.

Installation

The installation in Linux system is quite easy. I have just installed it into my Ubuntu 16.04 system using the following commands:

  • Add public key into your system
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

  • Add repository
     sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"

  • Update packages
        sudo apt update

  • Install docker community edition ( I am afraid to install enterprise edition, I hope it is also free, but I like the word community)
    sudo apt install docker-ce

  • Test installation
    sudo docker info
    sudo docker run hello-world

Do Interesting Stuffs

After successful installation of docker, it is good idea to do something interesting.  Docker comes with default image hello-world which does nothing but print a message.  The image are blueprints of application which form the basis of containers. After we run images, creates a container which runs the actual application. 

So, we need to download (or pull) the image first before we create instance of it. We  do that by using "docker pull" command.

sudo docker pull busybox 

Then, after pull completes, we can see the image using the following command:

sudo docker images

Now, we run the container 

sudo docker run busybox 

This creates container instance, since no command is given, it does nothing, and terminates the instance.  If we do something like this:

sudo docker run busybox echo "hello world"

This will print out the hello world in the console. 

Now, if we run the image using -it parameter (-it stands for interactive), then the instance does not terminate.  

sudo docker run -it busybox

We can verify the running of this using the following command:

sudo docker container ls

This shows the running instances.

 Remove instance

sudo docker rm container_id1, container_id2

or  to remove all exited instances:

sudo docker rm $(sudo docker ps -a -q -f status=exited)


Remove image 

sudo docker rmi image_id1, image_id2

or to remove all images

sudo docker rmi $(docker images -a -q)


Ubuntu 18.04

Now my interest is to pull ubuntu 18.04 image and create a container of it.

sudo docker pull ubuntu:18.04 (pull)
sudo docker images (check)
sudo docker run -it ubuntu:18.04 (run)
sudo docker container ls (verify container)

So, after running container you are in the bash terminal, where you have possibilities to install commands and tools from scratch.

There basic image does not come with all necessary command or tools. So, we have to install or configure ourselves.