Tech
Infected

Linux, OpenSource, Programming And Hacks

Jun 17, 2018

How to Create WIFI Hotspot from Ubuntu 18.04 Laptop

Jun 17, 2018
To create a wifi hotspot in ubuntu 18.04, you should be first connected via LAN.

The process is quite simple and can be done via GUI.

Step 1: 

Click on the top right buttons and click on the WiFi option. in the dropdown select Wifi-settings.

May 31, 2018

Python Program to Add two binary numbers using built function

May 31, 2018
Here we will see how to easily add two numbers in python3 using built-in functions.

please run this program with python3.

Steps:

1. Take input of the two binary numbers as string using the input function.
2. convert them into integers using int function passing the base 2
3. Add the integers
4. convert the sum into binary using the bin function

Same steps for subtracting, multiplication, or division, just change the operation in step 3

a = input("Enter 1st binary number: ")
b = input("Enter 2nd binary number: ")

#converting a and b into integer

a = int(a,2)
b = int(b,2)

#adding the integers

s = a + b

#sonverting the sum into binary

s = bin(s)

print(s)

May 29, 2018

How to show IP address in Ubuntu 18.04 (Connection Information)

May 29, 2018
As we know that Ubuntu 18.04 ships with Gnome Desktop by default. There used to be a Connection Information option in previous Unity Ubuntu versions which showed IP address, Netmask,  DNS address, and various other infos but it's no longer shown.

But you can view the connection information on Ubuntu 18.04 as follows.

May 26, 2018

Shell Script to Run Django Development Server Automatically

May 26, 2018
We all know how boring it can be to start the django development server each time. entering the same commands over and over. The good news is that you can write a simple shell script to do so. and after that you just need to run the shell script and yay! your django server is running automatically with just a little command. Cool!!

Let's say you have a Django project named project and a virtual environment named env inside a directory called project_folder

cd project_folder
source env/bin/activate
cd project
python manage.py runserver

save this script as script.sh or whatever you want.

Run this script using . (dot) rather than ./script.sh

We do this because if we run the script normally with a ./ then the cd command in the script file will get back to the current directory after changing it.

. script.sh



Tip: you probably wanna wanna place this script at your home directory and give a small name like dj.sh or anything so that it's easier to type in.

But it's better to make an alias of executing this script and place it at the end in your .bashrc file

nano .bashrc
alias dj='. $HOME/script.sh'

and now restart the terminal.

From now on, all you need to do is just type dj in the terminal and it will do the job for you!


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>

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

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

</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

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 settings.py

INSTALLED_APPS = (
    # Add compressor to the installed apps
    "compressor",
)

COMPRESS_ENABLED = True

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # other finders..
    'compressor.finders.CompressorFinder',
)

COMPRESS_ENABLED = True

#add filters
 
COMPRESS_CSS_FILTERS = [
    'compressor.filters.cssmin.CSSMinFilter'
]
COMPRESS_JS_FILTERS = [
    'compressor.filters.jsmin.JSMinFilter'
]


Usage

{% 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 %}

Result:
<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]
print(rev)

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