Linux, OpenSource, Programming And Hacks

May 22, 2018

How to upgrade Ubuntu 16.04 to 18.04

May 22, 2018
Ubuntu 18.04 aka Bionic Beaver was released on 26 April this year. This is a LTS (Long Term Support) Release. It was one of the most awaited release version.

In this tutorial we will see how to upgrade ubuntu 16.04 (Xenial Xerus) to 18.04

Ubuntu allows users to upgrade one LTS version to another. since ubuntu 16.04 is also an LTS version so it can be upgraded directly to 18.04. for non LTS version it is not possible.

May 18, 2018

How to Install Gummi LaTex editor for Ubuntu 18.04 / 16.04

May 18, 2018
Gummi is a Latex Editor. it is available for both Linux and Windows platform. Gummi has a Live preview, unlike command line tools where you need to compile the tex file to product the pdf. It supports insertion of tables and images via gui. Bibliography management is supported.

It is available for Linux Distributions like Debain, Ubuntu, Linux Mint, Fedora, Gentoo, Arch Linux..

Install in Ubuntu 18.04

sudo apt install gummi

Install in Ubuntu 16.04 / 16.10 / 17.04 / 17.10

sudo add-apt-repository ppa:gummi/gummi
sudo apt-get update
sudo apt-get install gummi

Apr 2, 2018

How to install Google Chrome on Ubuntu / Linux mint [via PPA]

Apr 2, 2018
Google Chrome, the most popular browser, is available for Linux. While Chromium, the open source version of chrome is there by default in ubuntu repository, we need to add google chrome source to the repository by ourself.

Follow the below steps to install Google Chrome in Linux mint / Ubuntu 14.04 , 16.04

Apr 1, 2018

How to compile and run Java program in Linux / Ubuntu Terminal

Apr 1, 2018
Writing a Java program is quite straight forward in Linux systems, no matter what linux distro (Linux Mint / Ubuntu / Debian / Arch Linux) you have, the steps will same except for step 1 which is installation, it may differ distro to distro

Here we will write, compile and execute a simple HelloWorld Program.

Mar 24, 2018

Ipython, an alternative Interactive Python interpreter [tutorial]

Mar 24, 2018
Ipython is an interactive python shell which can be used as a replacement for your default python interpreter.

Install Ipython

pip install Ipython

Launch Ipython

Just enter ipython in your terminal

aman@vostro:~$ ipython
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

Mar 23, 2018

Rearrange Bootstrap Column Order with Push and Pull Classes

Mar 23, 2018
Suppose you have three columns, left-sidebar, main-content, right-sidebar. when the page is opened on small screen size the left-sidebar will be stacked at the top followed by the main-content and right-sidebar.

What if you wanted to get the main-content at the top followed by the left-sidebar and right-sidebar?

This can be accomplished by the bootstrap column push and pull classes.

<div class="row">

 <div class="col-sm-8 col-sm-push-2">
  <div style="background-color:red;color:#fff">main-content</div>

 <div class="col-sm-2 col-sm-pull-8">
  <div style="background-color:blue;color:#fff">left-sidebar</div>

 <div class="col-sm-2">
  <div style="background-color:blue;color:#fff">right-sidebar</div>


on large display

on mobile display

Mar 3, 2018

Some Useful Tmux Shortcuts and Cheatsheet

Mar 3, 2018
Tmux is a terminal multiplexer. it's can be used to create several window panes. Create sessions and much more.
Tmux is particularly very useful on remote terminals, I like to use Vim as a text-editor with Tmux.

Open Tmux


Mar 2, 2018

Minify JavaScript / CSS with Django Compressor

Mar 2, 2018
Django Compressor minifies JavaScript and CSS files. It can combine several inline or linked files into cacheable static files. it also supports uglify wih yuglify compressor

Install Django Compressor

pip install django_compressor

In your

    # Add compressor to the installed apps


    # other finders..


#add filters


{% load compress %} 
{% compress css %}
<link rel="stylesheet" href="/static/css/example.css" type="text/css">
<style>p { font-size:5px; color:green;}</style>
<link rel="stylesheet" href="/static/css/example2.css" type="text/css" charset="utf-8">
{% endcompress %}

{% compress js %}
<script src="/static/js/example.js"></script>
<script> console.log("some msg"); function sample() { console.log("some function definition") }</script>
{% endcompress %}

<link rel="stylesheet" href="/static/CACHE/css/07786f58by27.css" type="text/css" />
<script type="text/javascript" src="/static/CACHE/js/70850ie6975h.js"></script>

Note: Make sure static root is defined or you will get an error something like this
django.core.exceptions.ImproperlyConfigured: COMPRESS_ROOT defaults to STATIC_ROOT, please define either

Feb 23, 2018

Automatically create OneToOneField in Django

Feb 23, 2018
The Django-annoying package contains various useful functions and AutoOneToOneField is one of them.

Using AutoOneToOneField a related object is automatically created when the parent object is created.

In this example, whenever a new user account is created, a corresponding Profile is also created

Important: The child object is not created unless it is accessed.

1. Install

pip install django-annoying

2. In your models

from django.contrib.auth.models import User
from annoying.fields import AutoOneToOneField

class Profile(models.Model):
    user = AutoOneToOneField(User, primary_key=True)
    name = models.CharField(max_length=255, blank=True)
    age = models.IntegerField(blank=True, null=True)

3. Accessing the Child Object

As I mentioned that the child object won't be created usless it is accessed.

so, in you view you might wanna do something like this.

def saveprofile(request):
    u = User.objects.get(username=request.user)
    print(u.player) #accessing child object

That's it!

Feb 22, 2018

3 Common ways to Reverse a String in Python

Feb 22, 2018
One of the very common problems in any programming language is how to reverse a String.

Let's see a few ways to do this in python.

1. Using String Slicing

well first of all the most easy way.. Here we are using the power of String Slicing. Just a single line command!

-1 at the last index means reading from end. and the first two empty index means that we are considering the whole string. 

mystring = "Hello World"
rev = mystring[::-1]

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