Redirect or block traffic based on country geographical location using Apache mod_geoip

In this config you will learn how to block or redirect web traffic based on the visitor’s country geographical location using Apache’s geoip mod.

Apache mod_geoip installation

Assuming that you already have Apache webserver installed and running we start by the installation of mod_geoip:

# apt-get install libapache2-mod-geoip
CENTOS/REDHAT/FEDORA ( epel enabled only )
# yum install mod_geoip.x86_64

Read more

An easy way to encrypt and decrypt large files using OpenSSL and Linux

Below is a quick config on how to to encrypt and decrypt large files using OpenSSL and Linux such as Redhat, Ubuntu, Debian, CentOS, Fedora etc. First, what you will need is a some sort of arbitrary file. Let’s create 1GB file now:

$ fallocate -l 1G large_file.img
$ ls -lh large_file.img
-rw-r--r--. 1 lrendek lrendek 1.0G Jan  2 16:40 large_file.img

Read more

How to transfer data over the network with nc (netcat) command on Linux

The nc ( netcat ) command can be used to transfer arbitrary data over the network. It represents a quick way for Linux administrators to transfer data without the need for an additional data transfer services such as FTP, HTTP, SCP etc. This config will show you an example on how to transfer data between to network hosts. We will be transferring data myfile.txt file from a localhost to a destination host with an IP address

Destination host

The nc command first needs to be started on the network host to which we need to transfer data. We will instruct nc to listen for an incoming request on user defined port number and once the client request comes receive the desired data. Pick the port number of your choice to ensure that it is not blocked by firewall and it is accessible from the source host.

$ nc -l -p 7555 > myfile.txt

Read more

How to obtain a laptop battery information and charging state on Linux

The following linux commands will help you to obtain the information about your laptop battery such as manufacturer, part type, capacity, voltage etc. First, tool which can be used for this job is dmidecode command. If you currently do not have dmidecode available on your Linux system you can install it by:

# apt-get install dmidecode
# yum install dmidecode

next, using dmidecode we can obtain some hardware information about our battery:

# dmidecode -t 22
# dmidecode 2.12
SMBIOS 2.6 present.

Handle 0x002E, DMI type 22, 26 bytes
Portable Battery
        Location: Rear
        Manufacturer: LGC
        Name: 42T4942
        Design Capacity: 93240 mWh
        Design Voltage: 11100 mV
        SBDS Version: 03.01
        Maximum Error: Unknown
        SBDS Serial Number: 073C
        SBDS Manufacture Date: 2012-03-23
        SBDS Chemistry: LION
        OEM-specific Information: 0x00000000

Read more

C++ pointer example diagram

C++ : Understanding pointers

Author: Lubos Rendek

Date: 10.09.2009

Update: 04.03.2010 – Section 7.2 was created to clarify relation between Pointers and Arrays in C++


This article is intended to all programing enthusiasts on all levels who do wish to understand pointers in C++ language. All code presented here is not a compiler specific and all examples will be written in plain ANSI C++. Debate about pointers can stretch for miles, and you would need to go really far to master it all. If you really want to run that far, this article gives you a clear understanding of fundamental concepts about pointers and prepares you for that journey. However, those who are new to C++ programming make sure that you are able to write and run your own C++ “hello world” program, and also it is recommended that you have a basic understanding of C++ functions and classes. If you need to refresh your knowledge about how to compile and run C++ program, use functions and classes, please read an appendix at the end of this document before you continue reading this article.

What is a Pointer?

Pointer is a variable that stores a memory address. OK, that is simple ! But, what is a memory address then? Every variable is located under unique location within a computer’s memory and this unique location has its own unique address, the memory address. Normally, variables hold values such as 5 or “hello” and these values are stored under specific location within computer memory. However, pointer is a different beast, because it holds the memory address as its value and has an ability to “point” ( hence pointer ) to certain value within a memory, by use of its associated memory address.

Retrieving a Variable’s Memory Address

OK, enough talking and let’s get down to the pointer business. To retrieve a variable’s memory address, we need to use address-of operator &.

#include <iostream>
int main()
using namespace std;
// Declare an integer variable and initialize it with 99
unsigned short int myInt = 99;
// Print out value of myInt
cout << myInt << endl;
// Use address-of operator & to print out
// a memory address of myInt

cout << &myInt << endl;

return 0;



The first line of the output contains an integer value 99 and on the second line, there is a memory address of myInt printed out. Please note that your output will be different.

Assigning a Variable’s Memory Address to a Pointer

Before we can assign a memory address to a pointer, we need to declare one. Declaring a pointer in C++ is as simple as to declare any other variable with one single difference. Asterix symbol ” * ” needs to be add and located after variable type and before a variable name. One rule has to be followed when assigning memory address to a pointer: pointer type has to match with variable type it will point to. One exception is a pointer to void, which can handle different types of variables it will point to. To declare a pointer pMark of type unsigned short int a following syntax is to be used:

#include <iostream>

int main()
using namespace std;

// Declare and initialize a pointer.
unsigned short int * pPointer = 0;
// Declare an integer variable and initialize it with 35698
unsigned short int twoInt = 35698;
// Declare an integer variable and initialize it with 77
unsigned short int oneInt = 77;
// Use address-of operator & to assign a memory address of twoInt to a pointer
pPointer = &twoInt;
// Pointer pPointer now holds a memory address of twoInt

// Print out associated memory addresses and its values
cout << "pPointer's memory address:\t\t" << &pPointer << endl;
cout << "Integer's oneInt memory address:\t" << &oneInt << "\tInteger value:\t" << oneInt << endl;
cout << "Integer's twoInt memory address:\t" << &twoInt << "\tInteger value:\t" << twoInt << endl;
cout << "pPointer is pointing to memory address:\t" << pPointer << "\tInteger value:\t" << *pPointer << endl;

return 0;


pPointer's memory address:              0xbff43314
Integer's oneInt memory address: 0xbff43318 Integer value: 77
Integer's twoInt memory address: 0xbff4331a Integer value: 35698
pPointer is pointing to memory address: 0xbff4331a Integer value: 35698

C++ pointer example diagram

The diagram above is a high level visual abstraction of how are variables stored within a computer memory. Pointer pPointer starts at memory address 0xbff43314 and takes 4 bytes. Pointer pPointer holds as a value a memory address of a short int twoInt ( 2 bytes ) which is 0xbff4331a. This address is stored as a binary data within a pointer’s memory space allocation. Therefore, dereferencing a pointer with a memory address 0xbff4331a will indirectly access a value of twoInt which is in this case a positive integer 36698.

Read more

How to convert documents between LibreOffice and Microsoft Office file formats on Linux

In this config you can learn how to convert documents format between LibreOffice and Microsoft Office file formats on Linux. The preferred tool to use for a file format conversion between LibreOffice and Microsoft Office is unoconv. Let’s start with the installation of unoconv package:

# yum install unoconv
# apt-get install unoconv

and create some LibreOffice document document.odt and spreadsheet spreadsheet.ods to play with:

$ file document.odt 
document.odt: OpenDocument Text
$ file spreadsheet.ods 
spreadsheet.ods: OpenDocument Spreadsheet

Read more

move vim text editor cursor left with h, move vim text editor cursor right with l, move vim text editor cursor up with k ,move vim text editor cursor down with j

Vim Tutorial


This tutorial has been written for both vi and vim. It starts with real basics, such as cursor navigation and ends with more advanced techniques like merging files.

For every section of this tutorial there is a short video with hints to help you understand how vim / vi works. Even that I have divided this tutorial into parts from novice to the expert user, there is plenty more what vim can do to make your work with vim editor easier and more efficient.

However completing this tutorial you will give sufficient knowledge about vim / vi and its features for your daily tasks.

Vim Novice level ( Vim Basics )

Moving cursor around

 move vim text editor cursor left with h, move vim text editor cursor right with l, move vim text editor cursor up with k ,move vim text editor  cursor down with j

In vim you can move cursor around with following keys h, l, k, j which is left, right, up and down respectively.

You can move cursor around also with arrow keys, however this is possible only if they are available.

Vim was designed for all kinds of terminals where arrow keys may not be available for you. Moreover, once you get used to using vim with h, l, k, j you will move more quickly than using arrow keys.

Open some text file and try use above keys now:

vim yourfile.txt

NOTE: You do not have to create a file prior to execution of the above command. If the file does not exists it will be created. If the file does exists it will be opened.

Read more

Remove all containners based on docker image name

How can I remove all docker containers based on a docker image name. I do not wish to remove all available containers, only the those which are based on particular image. For example I would like to remove all containers based on image centos:7.

To remove all docker containers based on centos:7 run the following linux command:

# docker ps -a | awk '{ print $1,$2 }' | grep centos:7 | awk '{print $1 }' | xargs -I {} docker rm {}

Read more