Monday, 2 October 2017

How to exclude files from git using gitignore

During the development phase of the software in addition to the sources there are files that you want to exclude from git as binary files, eclipse settings files etc...
All these files should not be edited, so we can exclude them through a suitable configuration.

Create a local .gitignore 

A soluntion a this issue is the creation of a file with name ".gitignore" in main directory of your repositoriy.

Example

An example of gitignore file is the following:
# Compiled source #
###################
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
*.7z
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs #
########
*.log

# OS generated files #
######################
.DS_Store*
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

Refresh cache about gitignore

If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:
 git rm --cached <FILENAME>

Create a global .gitingore

Alternatively you can also create a global .gitignore file, which is a list of rules for ignoring files in every Git repository on your computer. For example create a file like local .gitignore in home with name ".gitignore_global" and run the following command into your shell:
 git config --global core.excludesfile ~/.gitignore_global

Thursday, 28 September 2017

Bash commands for Navigation and File Management

Current working directory - pwd

To find out where your home directory is in relationship to the rest of the filesystem, you can use the pwd command. This command displays the directory that we are currently in.
$ pwd

List information about the files - ls

To display the directory that you are in, you use "ls" command.
$ ls
For instance, to list all of the contents in an extended form, we can use the -lflag (for "long" output):
$ ls -l

Change the working directory - cd

Begin by going back to the mydirectory directory by typing this:
$ cd mydirectory
You can use absolute or relative path.

Viewing a file - cat 

Use the "cat" command for read the contents of a file. This command concatenates one or more files to standard output. Example: 
$ cat myfile.txt

Create a file - touch

The "touch" command creates a file in your filesystem. Example:
$ touch myfile.txt

Create a directory - mkdir

The "mkdir" command creates a new directory in your filesystem. Example:
$ mkdir mydirectory
To tell mkdir that it should create any directories necessary to construct a given directory path, you can use the -p option
$ mkdir -p dir1/dir2/mydirectory

Moving and Renaming Files and Directories - mv

You can move a file to a new location using the mv command. For example, you can move myfile into the dir1 directory by typing:
$ mv myfile dir1
So to rename the dir1 directory to directory1:
$ mv dir1 directory1

Copy files and directories - cp

The cp command can make a new copy of an existing file or directory. For example, you can copy myfile.txt into same directory but with a different name (myfile2.txt):
$ cp myfile.txt myfile2.txt
Instead if you can copy a directory, use "-r" option:
$ cp -r mydir new_mydir

Remove a file - rm

The rm command remove a file. For example, you can remove myfile2.txt with the following command:
$ rm myfile2.txt

Remove a directory - rmdir

The rmdir command remove a directory. For example, you can remove new_mydir with the following command:
$ rmdir new_mydir
Alternatively you can use the following command:
$ rm -r new_mydir

Remove all files (recursively)

You can remove recursively all files with a precise name (or regular expression) from a specific path. Example: you can remove all .svn files from a your workspace, so you can execute the following command into workspace directory:

$ find . -name .svn -exec rm -rf {} \;

Find all snapshot version in a maven project
$ find . -name pom.xml | xargs grep "SNAPSHOT"

Disk Usage - du

Disk Usage - report the amount of disk space used by the specified files and for each subdirectory
$ du -h

Internal Links

May be of interest to you:

Monday, 25 September 2017

How to store your git credentials

Use the following command:
 git config --global credential.helper store
Next time when you will be prompted again your credentials, It will be created ".git-credentials" file in your home.
Now you never have to enter your credentials.

Storage format

The .git-credentials file is stored in plaintext. Each credential is stored on its own line as a URL like:
 https://<user>:<password>@<hostname>

Example

Store your password in your home.

1
2
3
4
5
6
7
8
$ git config --global credential.helper store
$ git push http://yourserver.com/repo.git
Username: <type your username>
Password: <type your password>

[several days later]
$ git push http://yourserver.com/repo.git
[your credentials are used automatically]

Friday, 15 September 2017

How to use ssh keys with putty

Overview

PuTTY is a free and open-source terminal emulator, serial console and network file transfer application. It supports several network protocols, including SCP, SSH, Telnet, rlogin, and raw socket connection. It can also connect to a serial port. The name "PuTTY" has no definitive meaning.
PuTTY was originally written for Microsoft Windows, but it has been ported to various other operating systems. Official ports are available for some Unix-like platforms, with work-in-progress ports to Classic Mac OS and macOS, and unofficial ports have been contributed to platforms such as Symbian, Windows Mobile and Windows Phone.

See the following guide for installation guide.

SSH Configuration

Open your putty and click on "Auth" item (1), now click on "Browse..." button (2) and add your private key.
Click on "Loggin" item (3) and put the hostname (4) and saved session name (5). Click on "Save" button (6) to save and finally click on "Load" button to ssh connection.
A good suggestion, in step 4 use the following format:
 <sshuser>@<hostname or ip>
Example:
 myuser@myserver

Internal Links

Thursday, 14 September 2017

java.lang.OutOfMemoryError: GC overhead limit

Java runtime environment contains a built-in Garbage Collection (GC) process. In many other programming languages, the developers need to manually allocate and free memory regions so that the freed memory can be reused.
Java applications on the other hand only need to allocate memory. Whenever a particular space in memory is no longer used, a separate process called Garbage Collection clears the memory for them. How the GC detects that a particular part of memory is explained in more detail in the Garbage Collection Handbook, but you can trust the GC to do its job well.

The cause

The java.lang.OutOfMemoryError: GC overhead limit exceeded error is the JVM’s way of signalling that your application spends too much time doing garbage collection with too little result. By default the JVM is configured to throw this error if it spends more than 98% of the total time doing GC and when after the GC only less than 2% of the heap is recovered.
The java.lang.OutOfMemoryError: GC overhead limit exceeded error is displayed when your application has exhausted pretty much all the available memory and GC has repeatedly failed to clean it.

Example

In the following class creates a “GC overhead limit exceeded” error by initializing a Map and adding key-value pairs into the map in an unterminated loop:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
package com.blogspot.informationtechnologyarchive;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class ExampleGCOverheadLimit {

 public static void main(String[] args) {
  Map<Integer,String> map = new HashMap<Integer,String>();
     Random r = new Random();
     while (true) {
       map.put(r.nextInt(), "value");
     }
 }

}
As you might guess this cannot end well. And, indeed, when you launch the above program with:
java -Xmx100m -XX:+UseParallelGC ExampleGCOverheadLimit
You soon face the java.lang.OutOfMemoryError: GC overhead limit exceeded message.

Solution

As a solution (or rather to consider it as a workaround), if you just wished to get rid of the “java.lang.OutOfMemoryError: GC overhead limit exceeded” message, adding the following to your startup scripts would achieve just that: 
 -XX:-UseGCOverheadLimit

Wednesday, 13 September 2017

How to enable the copy paste in Ubuntu VM with VirtualBox guest to Windows

Open VirtualBox, select your Ubuntu VM and click on Settings button:
Now, apply the following settings:
Start your Ubuntu VM and via shell install the following virtualbox packages with this command:
 sudo apt-get install virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
Shut Down the Ubuntu VM, close and reopen VirtualBox, after all start your Ubuntu VM.
DONE.

Internal Links

May be of interest to you:

Tuesday, 12 September 2017

How to deploing jars to your artifactory server

The build phase generates one or more artifacts, maven provides a local repository where to store these artifacts but It is possible to store the artifacts in a remote repository as an Artifactory server.
For deploying jars to your artifactory server you can add the following configuration in your settings.xml (in $HOME/.m2). This configuration stores the credentials for the authentication into artifactory repositories.
<servers>     .......     <server>       <id>central</id>       <username>user</username>       <password>password</password>     </server>     <server>       <id>snapshots</id>       <username>user</username>       <password>password</password>     </server>     ....... <servers>
Now yoiu can add the repository configuration always in settings.xml.
<repositories> ......   <repository>     <snapshots>         <enabled>false</enabled>     </snapshots>     <id>central</id>     <name>libs-releases</name>     <url>http://myartifactory:8080/artifactory/libs-releases</url>   </repository>   <repository>     <snapshots>         <enabled>true</enabled>         <updatePolicy>always</updatePolicy>         <checksumPolicy>fail</checksumPolicy>     </snapshots>     <id>snapshots</id>     <name>libs-snapshots</name>     <url>http://myartifactory:8080/artifactory/libs-snapshots</url>   </repository> ...... <repositories>
You can execute the following command:
$ mvn deploy
If your maven project version has a SNAPSHOT version then the jars will be deployed on "libs-snapshots" repo, else they will be deployed in "libs-releases".
If you want deploy the jars in a repo not configured in settings.xml file, you can use -DaltDeploymentRepository option. Example:
$ mvn deploy -DaltDeploymentRepository="otherRepoReleases::default::https://otherartifactory:8180/artifactory/otherRepoReleases"
Surely the repository requires authentication that you can configure in settings.xml as shown above.

Welcome

Hello everybody, Welcome in my blog called "Information technology archive". Obviously the topics will be related to Informatio...