Linux, OpenSource, Programming And Hacks

Jan 14, 2018

How to Install SQLite3 in Ubuntu / Linux Mint

Jan 14, 2018
SQlite is an Embedded Relational Database Management System. SQlite does not require a server to run unlike mysql or other popular dbms.

To install Sqlite3 in Ubuntu / Linux Mint issue the following commands

This will work for Ubuntu 14.04 and above

sudo apt-get update
sudo apt-get install sqlite3 libsqlite3-dev

Jan 12, 2018

Install TypeScript Syntax highlighting in Sublime Text Editor

Jan 12, 2018
We will need the TypeScript Package to get Syntax highlighting to work. we will install the package using Package Control.

So, first go ahead and install Package Control

Now, go to preferences, where you can now find Package Control option, click on it .

Jan 11, 2018

Python Program to Check if a number is FIbonacci

Jan 11, 2018
In Fibonacci Sequence, every previous two numbers gives the next number.

the first 10 Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 35

In this python Program we will see how to test if a number given by user belongs to the Fibonacci sequence.

If the given number is n then any of 5n*n + 4 or 5n*n - 4 or both should be a perfect square to be a Fibonacci number.

Python Code:

import math

def CheckPerfect(x):
  i = int(math.sqrt(x))
  return (x == i*i)

def CheckFibo(n):
  if(CheckPerfect(5*n*n + 4) or CheckPerfect(5*n*n - 4)):
    print("Not Fibonacci")

CheckFibo(89) #this returns true, 89 is Fibonacci

you can suggest better algorithm for this in the comments!

Jan 10, 2018

Python Program to check if a number is Perfect Square

Jan 10, 2018
A number that can be expressed as the product of two equal integers is a Perfect Square number.

for example: 25 can be expressed as 5 x 5

In the given python3 code we take a user input and take out the square root and convert it into integer. if square root value multiplied by itself equals the user given number then its proved to be a Perfect number else not. 

import math

n = int(input())

i = int(math.sqrt(n)) #sqrt function returns float so typecasting to int

if(n == i*i):
  print("perfect Square: %d * %d = %d"%(i,i,n))
  print("Not Perfect Square")

Please comment below if you have a better algorithm than the given one.

Jan 8, 2018

How to Fix - Operational Error: cannot open database in Django Sqlite3

Jan 8, 2018
This may be a permission problem.

the database file must be writable to the user

you need to grant permission to db.sqlite3

here, myproject is the folder which contains db.sqlite3 file

chmod 664 /path/to/myproject/db.sqlite3
sudo chown :www-data /path/to/myproject/db.sqlite3 
sudo chown :www-data /path/to/myproject

also give necessary permissions to the folder that contains the sqlite3 database file. the database engine should be able to write a lockfile to the parent directory of the database file.

sudo chmod 775 /path/to/myproject

Dec 28, 2017

Get Free SSL certificate with Let's Encrypt on Ubuntu Apache Server

Dec 28, 2017
Let's Encrypt is an open certificate authority and provides free SSL Certificates. It's popular for it's simplicity to setup. It's been founded by Mozilla, Cisco and many more.

The setup process is very simple, I have explained it in 3 steps:
In the bottom section I have also mentioned the problems I faced and the solutions that worked.

Make Sure that your website is running on Apache server configured through VirtualHosts and specifies ServerName

Dec 25, 2017

How to link a custom domain name to AWS EC2 instance

Dec 25, 2017
if you have created your Amazon AWS EC2 instance, you can now access it on the web using your given public ip or public DNS (something like, you can find these in the description of the instance.

But you need to access your website just using you own domain like

Here are the steps to do so very easily:

Dec 24, 2017

How to setup a Static IP (Elastic IP) Address for AWS EC2

Dec 24, 2017
When you create an Amazon AWS EC2 instance, you are given a Public IP which you can use for remote login via SSH or Putty and of course to access on your browser. But the problem is that the Public IP keeps changing each time you restart your instance.

To get a fixed IP, the solution is to use an Elastic IP

Step1: You can find Elastic IPs option under the EC2 Dashboard (left sidebar). click on it.

Step 2: Click on 'Allocate new Address' button, you will get a new allocated IP

Step 3: Now, Click on the 'Actions' button and then click on 'associate Address' option.

you will get an option to select the EC2 instance that you want to get associated with the  newly allocated Elastic IP address.

That's it!

Note: Make sure you don't leave the Elastic IP unused, or you will be charged!

Dec 9, 2017

How to install Apache2 Server in AWS EC2 Linux

Dec 9, 2017
After you have created and launched your EC2 instance you must be wondering what to do next?
if you enter your instance ip in your web browser nothing will show because you need to install a server to see some action!

It's quite simple too!

I am showing all the steps on the Ubuntu EC2 instance but it will be same on any Linux instance.

Dec 5, 2017

Place a static file in root directory in Apache Server

Dec 5, 2017
Sometimes you are required to place files like sitemaps or other files in the root location.

Specially while using frameworks like Django, It can be bit tricky to do so within the framework.. So this method will flawlessly irrespective of which framework you are using.

So, If you are running Apache server, it's quite easy

Just open up your Apache Config file and add the following line at the bottom of that file.

Alias /example.txt /path/to/example.txt

Now restart your apache server.

After this you can access the file kept at /path/to/example.txt as /example.txt

Quite easy!

In ubuntu 16.04 you can find the config file here: /etc/apache2/apache2.conf

Sep 27, 2017

How to Install and use FFmpeg in Ubuntu 16.04

Sep 27, 2017
FFmpeg is a command line tool for video and audio conversion. It can also capture from a live audio or video source. It is cross-platform, available for Linux, Mac OS X, windows and more

Install ffmpeg in Ubuntu by entering these commands in the terminal (Ctrl +Alt + T):

sudo apt update
sudo apt install ffmpeg

Sep 16, 2017

Merge Sort Program in Python

Sep 16, 2017
We will look at the Merge Sort Algorithm which is used to sort an unsorted list. The input list is divided into two parts and they are solved recursively and then they are merged.

Worst Case Time Complexity: O(n log n)

Worst Case Space Complexity: O(n)

Merge sort is a divide and conquer algorithm.

1. We are given an unsorted list of n numbers 
2. Divide it into two array of equal size
3. Again Divide those two into another two array of equal size
4. Keep on dividing it until one element is left in each array.
5. Keep Merging the sub arrays to produce sorted arrays until there is only one array remaining.. This will be our sorted array.

Aug 10, 2017

Install guvcview (webcam recorder) in ubuntu 16.04 / Linux Mint

Aug 10, 2017
Guvcview is a webcam recorder software for Linux. Its the best recorder I have come so far.
Its simple and uses less resources compared to other webcam applications like Cheese or KDE Kamoso.

It has a two window interface one for just displaying the video and the other for different controls and settings.

Aug 9, 2017

Python Program to Generate Fibonacci Series using Recursion

Aug 9, 2017
Fibonacci Series: A sequence of numbers in which each number is the sum of the previous two numbers.

First 10 Fibonacci numbers: 0,1,1,2,3,5,8,13,21,34,...

In the following python program we have used recursive function to find out the Fibonacci series up to a given term.

Jul 21, 2017

Understand Python Dictionary (key-value pair / Hash Map)

Jul 21, 2017
This tutorial is about Python dictionary which is data-structure representing  key-value pairs, you can also call it a HashMap.

One of the very common use of hashmap is finding frequency of characters in a string

Basically a dictionary is like a list but instead of integer index it can be of any type

to define a dictionary we use a key-value pair with a colon between them.

in the example below, "one" maps to 1

also note that a dictionary is un-ordered, it may not show the items in the order it was defined.