Install XAMPP stack on Ubuntu 16.04 using terminal

Apache is the widely used web server, and PHP is a dominant technology when it comes to CMS frameworks i.e. WordPress, Drupal, etc. For this reason the deployment of the stack has been made effortless with XAMPP PHP development environment. XAMPP is an acronym, where X stands for any operating system (WAMP for Windows, LAMP for Linux), A for Apache web server, M for MySQL or MariaDB database engine, and PP stands for PHP and Perl. The post is about setting-up PHP development environment XAMPP on Ubuntu 16.04, suing terminal.

Step 0 – Login and update

First of all login into your Ubuntu machine using SSH – for a regular it’s recommended to add your SSH public key.
ssh <username>@<hostname/IP>

Continue reading “Install XAMPP stack on Ubuntu 16.04 using terminal”

All you need to know about SSH


SSH stands for Secure SHell, a tool developed by SSH Communication Security Ltd, for secure remote log-in and command execution. It’s a secure alternative of it’s predecessors rlogin, rsh, etc. SSH has become industry de-facto for securely communicating with remote machines i.e. the entire session is encrypted.
The SSH is based on public-key cryptography (also known as asymmetric cryptography), a cryptography system employing key pair i.e. a public key which is meant to be shared, and private key which has to be kept safe and secret, only known to the owner. This pair serves two purpose 1. authentication, the public key verifies the owner of the paired private key, and 2. encryption, the public key encrypts the message, and only the paired private key can decrypt it. In simple words, you can share your public key (content of ~/.ssh/ with anyone via email, for example: to access a remote machine securely and without password, all you need to do is copy your public key to authorized_keys (default – ~/.ssh/authorized_keys) file.

Continue reading “All you need to know about SSH”

DB partition trigger with PostgreSQL

Database partitioning is about logically splitting one large table into smaller physical pieces, such that improving query performance.  DB partitioning is a good alternate for indexing multiple columns, reducing index size, hence the memory in use. Few common pros of database partitioning:
  • Improved performance – data operations (CRUD) can be performed on a smaller volume of data, for example, in case of collecting data overtime, putting old data in separate partition might help with performance.
  • Bulk create and delete can be efficient by adding or removing separate partitions.
  • Time based partition can be helpful in cleaning old seldom-used data i.e. month based partition we can simply set a cron job for cleaning 12 month old partition, without effecting the table portion heavily in use for ADD, UPDATE, etc.
  • Improved scalability – In case of very large tables, you can partition and have them hosted on a separate server.
There are 2 main approaches to database partitioning:
  • Horizontal partitioning (Sharding) – a table is split horizontally, such that each partition is a subset of the table, having the same schema (i.e. number of fields/columns).
  • Vertical partitioning – a table is split on the fields/columns, such that each subset has separate schema. A common use-case for vertical partitioning is to partition table fields on the basis of pattern of use i.e. frequently accessed fields are to be grouped together, and the less frequently accessed are put in a separate partition.

This blog post is about setting automatic horizontal partitioning (month based) on a table in PostgreSQL.
The high-level steps are:
  1. Create table, or select an existing one.
  2. Execute partitioning function or procedure
  3. Table trigger – to call the partition procedure.
  4. View for parent-child tables (optional)
  5. Verification.

Step 1 – Create Table

CREATE TABLE partition_test(id BIGINT, created_datetime DATE);
Create table

Step 2 – Trigger function

CREATE OR REPLACE FUNCTION test_partition_function() RETURNS trigger AS
partition_date TEXT;
partition TEXT;
partition_date := to_char(NEW.created_datetime,'YYYY_MM');
partition := TG_RELNAME || '_' || partition_date;
IF NOT EXISTS(SELECT relname FROM pg_class WHERE relname=partition) THEN
RAISE NOTICE 'A partition has been created %',partition;
EXECUTE 'CREATE TABLE ' || partition || ' () INHERITS (' || TG_RELNAME || ');';
EXECUTE 'INSERT INTO ' || partition || ' SELECT(' || TG_RELNAME || ' ' || quote_literal(NEW) || ').* RETURNING id;';
COST 100;
partition function

Step 3 – Table trigger

CREATE TRIGGER partition_test_trg
AFTER INSERT ON partition_test
FOR EACH ROW EXECUTE PROCEDURE test_partition_function();
table trigger

Step 4 – Viewing the partition (optional)

CREATE VIEW show_partitions AS
SELECT nmsp_parent.nspname AS parent_schema,
parent.relname AS parent,
nmsp_child.nspname AS child_schema,
child.relname AS child
FROM pg_inherits
JOIN pg_class parent ON pg_inherits.inhparent = parent.oid
JOIN pg_class child ON pg_inherits.inhrelid = child.oid
JOIN pg_namespace nmsp_parent ON nmsp_parent.oid = parent.relnamespace
JOIN pg_namespace nmsp_child ON nmsp_child.oid = child.relnamespace
WHERE parent.relname='partition_test' ;
db view

Step 5 – Verification (optional)

Let’s test using the show_partitions view, if we have any partitions yet
select * from show_partitions;
view partition

insert in partition_test

insert into partition_test values (1, '2018-01-19');

Few more inserts for the same month

insert into partition_test values (2, '2018-01-22');
insert into partition_test values (3, '2018-01-29');

Continue reading “DB partition trigger with PostgreSQL”

Install Python 3.6 on Ubuntu 14.04 and 16.04 LTS

A regular Ubuntu release comes up with 9 months of support, except the LTS (Long Term Support) versions.  Ubuntu 14.04 and 16.04 being the LTS are still widely in use at production level. Being a Python developer the first thing I need to on having a fresh Ubuntu 14.04, or 16.04 machine is update Python. Ubuntu 14.04 has Python 3.4 and 16.04 comes with Python 3.5. This blog post is about installing Python 3.6 on your Ubuntu 14.04, or 16.04 LTS.

Continue reading “Install Python 3.6 on Ubuntu 14.04 and 16.04 LTS”

Allow remote connections to PostgreSQL

PostgreSQL (aka Postgres), is an open-source SQL relational database management system (RDBMS). These RDBMS are the key component for the majority of all the web sites and web applications, providing an efficient way to persist, organize, and access information.
The last blog was “Install PostgreSQL 9.6 on Ubuntu 14.04, or 16.04 LTS” . By default postgresql allows connections only from the localhost ( i.e. any service on the same machine, only. So, a necessary step in PostgreSQL installation is to allow remote connections.

Continue reading “Allow remote connections to PostgreSQL”

Install PostgreSQL 9.6 on Ubuntu 14.04 or 16.04 LTS

PostgreSQL (aka Postgres), is an open-source SQL relational database management system (RDBMS). These RDBMS are the key component for the majority of all the web sites and web applications, providing an efficient way to persist, organize, and access information.
In the blog, I’ll demonstrate, how to install Postgres 9.6 for Ubuntu 14.04, 16.04 LTS.

Step 1: Add Postgresql repository

$ sudo add-apt-repository "deb $(lsb_release -sc)-pgdg main"
$ wget -q -O - | sudo apt-key add -

Continue reading “Install PostgreSQL 9.6 on Ubuntu 14.04 or 16.04 LTS”

Install Node.js, npm, and Angular on CentOS 7.x


Node.js is a cross-platform, open-source JavaScript library for server-side, contrary to previous practice of using JavaScript primarily for client-side scripting by embedding the scripts in a webpage’s HTML. Node.js provides asynchronous I/O capability out of the box with it’s event-driven architecture. Node.js has been adopted by major corporations, including IBM, LinkedIn, Microsoft, Netflix, Paypal, GoDaddy, Walmart, Cisco systems, a lot more.


NPM is the package management utility for the JavaScript programming language i.e. Node.js, Angular. It provides a command-line client for consuming and distributing the JavaScript modules from the remote registry . Easiest (most common way) to install npm is installing the Node.js, it has it as the default package manager. Currently npm registry has 347,184 packages, and there’s no approval process for submission of the package, you have to check the number of downloads and depending packages as a assurance of a good quality module. For more you can check the npm page.

Continue reading “Install Node.js, npm, and Angular on CentOS 7.x”

Apache Spark and PySpark on CentOS/RHEL 7.x

What is Apache Spark

You may have noticed, wherever there is a talk about big data the name Apache Spark eventually comes up, in simplest words it’s a large-scale data processing engine. Apache Spark is a fast data processing framework with provided APIs to connect and perform big data processing. Spark being the largest open-source data processing engine, has been adopted by large companies – Yahoo, eBay, Netflix, have massive scale Spark deployments, processing multiple petabytes of data on clusters of over 8,000 nodes.
Apache Spark can be started as a standalone cluster (which we’ll be doing for this tutorial), or using Mesos or YARN as cluster managers. Spark can work with data from various sources, AWS S3, HDFS, Cassandra, Hive (structured data), HBase, or any other Hadoop data source. Above all what makes Spark high in-demand is the included libraries MLib, SQL and DataFrames, GraphX, and Spark Streaming, to cater the main data processing use-cases, such that users can combinely use all these libraries in the same application.

Continue reading “Apache Spark and PySpark on CentOS/RHEL 7.x”

Ruby Kernel for Jupyter Notebook

Jupyter notebooks are nice way to keep your code, diagrams, documentation together, mostly in a single file, which is also executable i.e. can run/interpret your code in it, and also have the result saved as it is. Here’s blogpost for installing Jupyter Notebook – today I’ll share how to use Ruby kernel with Jupyter Notebook i.e. executing Ruby code inside the notebooks.
To create notebooks that can execute Ruby code we need to integrate Ruby kernel, the 3 simple steps are:
  • Install Jupyter
  • Install Ruby
  • Install iruby

Continue reading “Ruby Kernel for Jupyter Notebook”

Install latest Ruby version using rbenv

Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. Yukihiro “Matz” Matsumoto created it in the mid-1990s, using his influence from other prpgramming languages i.e. Perl, Ada, Lips, Eiffel, and Smalltalk. Ruby was released in 1995. Like Python (released few years earlier), ruby also has dynamic typing and implicit memory management

Continue reading “Install latest Ruby version using rbenv”