Multiple versions of Python

Do you have multiple versions of Python to be installed? Do you have additional python packages that must be used in separate versions of Python installed on the system?

Use Virtual Environments!

Today we will see how to setup 2 different versions of Python environment.

  • Install python

    sudo apt install python

  • Install pip (python’s package management system):

    sudo apt install python-pip

  • Upgrade pip:

    pip install –upgrade pip

  • Install virtualenvwrapper by running this command:

    pip install virtualenvwrapper

  • Before we can create a virtualenv, we need to run the virtualenvwrapper script. We can find the location of virtualenvwrapper script by running the following command:

    which virtualenvwrapper.sh

  • Execute the script as:

    source ~/.local/bin/virtualenvwrapper.sh

  • Make a virtual environment with following command

    mkvirtualenv -p <location of python3.5> <name_of_env>

    For example for creating virtual env for python 3.5 named ‘venv35’, run:

    mkvirtualenv -p python3.5 venv35

    It will take activate the virtualenv for us directly. To deactivate it, enter:

    deactivate

  • Similarly, we can create another environment for python 2.7 named ‘venv27’, run:

    mkvirtualenv -p python2.7 venv27

  • To run, any environment, run the command:

    workon <env name>

    For exaemple, to run venv27, use:

    workon venv27

Enjoy!

VirtualBox on Windows (Host)

Hi there!

In this post, we will setup VirtualBox on Windows with Linux as a Guest OS. Follow the steps to begin:

Downloading and Installing VirtualBox

Download the virtual box setup from here. Under VirtualBox binaries, select package for Windows Hosts. Also, download VirtualBox Extension Pack, we will need it later for when we setup our Guest OS.

Also we need to download our favorite Linux distro. I am using Ubuntu latest version (as of this date), you can get it from here.

We will run VB setup wizard and install VirtualBox on our drive (you can specify the location where you want to install it).

Install Extension Pack

Run VirtualBox for the first time. Go to File > Preferences or use shortcut key (Ctrl + G). In the Preferences dialog box, go to Extensions.

Add the extension pack that we downloaded earlier. We can do so by either Right Click > Add Package or pressing the button (Add New Package) on the right hand side of the window.

Once weagree to the terms of conditions, we’ll able to install the extension pack.

Press Ok to close the Preferences dialog box.

Creating a New Virtual Machine

Click on New button to create a new virtual machine (VM). It will open up a wizard to create a VM. Enter the name for our VM (I’m using ‘Ubuntu 16.04.2’ same as the version of my Ubuntu). Click Next.

Select the amount of RAM we want to assign to this VM. I’ve assigned 8GB as I have 32GB but you can assign as per your preference. Click Next.

It will ask us whether we want to add virtual hard disk to this machine or not. We will make sure to select ‘Create a virtual hard disk now‘ option before we click Create button. Select the size of the hard disk and then we are done.

Installing OS on VM

Right click on the VM we just created and select Settings. In General Settings, go to Advanced tab, change ‘Shared Clipboard‘ and ‘Drag’n’Drop‘ to Bidirectional.

In Storage settings, we can see that under Controller: IDE it shows Empty. Select this Empty option and we will see that Attributes on the right hand side changes. Click on the CD icon next to the Optical Drive option and select the Choose Virtual Optical Disk File option to choose Ubuntu Iso we downloaded.

Check Live CD/DVD option below that as well. And then Press Ok to close the Settings.

Start the VM by right clicking and selecting the Start > Normal Start.

Now we can install Ubuntu on this Machine.

Setting things in Ubuntu (Guest)

Once we have installed Ubuntu on our VM, we will start it. Now go to Devices > Insert Guest Additions CD Image. It will ask to run, then enter your password to install it. Then restart Ubuntu after it is installed.

Go to Devices > Shared Folders > Shared Folders Settings. Right click and then select Add Shared Folder. Select the folder path that we want to share. Make sure you select Auto mount and Make Permanent and press Ok.

Shut down the Ubuntu OS.

Restart your VM, and voila your system is ready with Shared Folder

Note: If you get Permission denied error on accessing the shared folder, just add your username to vboxsf group using command:
sudo adduser <username> vboxsf

Disabling Ads in uTorrent

uTorrent is a lightweight torrent client for Windows, Mac, Android and Linux. The application is awesome but sometimes it annoys you with the the sponsored ads that keep showing on the interface.

ads

Now most of us want a clean interface and not boggled down by the ads. So here is what you can do to disable these ads.

  • Go to Preferences in the Options Menu. Or simply press Ctrl + P. This will open up the Preferences dialog box.
  • Go to Advanced tab (choose from left hand side hierarchy) as shown in the following figure. You will see the list of options available in this.preferences
  • Now, enter “offers” in the Filter Tab without the quotes and you will see the list of options that has ‘offers’ keyword included in them.
  • Scroll down and look for the “offers.left_rail_offer_enabled“. You will see that its value is true. search1
  • We want to disable this option so change its value to false and press OK.
  • Similarly, disable “gui.show_plus_upsell” as well. And if you want to close the top ad bar, disable “offers.sponsored_torrent_offer_enabled“.
  • Restart uTorrent.

And voila you can see that the ad box has disappeared. result

Enjoy! 🙂

Setting Up Development Environment for LMMS: QtCreator

This guide is for the new developers who want to begin developing for LMMS.

This tutorial assumes that you have already built/compiled LMMS on your system(presumed Linux but the steps could be applied for other OS albeit not as it is), and if not please follow the guide: Compiling LMMS

We will work with QtCreator and learn how to setup our Development Environment. Download the QtCreator from the official website.

Once you have installed QtCreator, we are ready to move forward.

  1. Launch QtCreator.
  2. Click on File>Open File or Project.
  3. Now browse to your ‘lmms’ directory and select on the file ‘CMakeLists.txt’, eg: /home/username/lmms/CMakeLists.txt
  4. A dialog box may appear asking you to specify the build directory, in here specify the folder ‘build’ in your ‘lmms’ directory that was created while compiling LMMS, eg: /home/username/lmms/build
  5. The Project will open, and if not it may ask for the executable file which you can specify as written below.
  6. Open ‘Options’ under Tools in the Menu Bar.
  7. In this dialog box, select ‘Build & Run’, where you can specify the build directory once again if you haven’t already done so.
  8. Under CMake tab, browse for the executable. Enter the path for the executable: /home/username/lmms/target/bin/lmms.

Once the project is opened and linked, you can build and run the project as you please.

Happy Development.

OpenSceneGraph on Linux

Welcome to this tutorial for running OpenSceneGraph on Linux (Debian based) machine. I’m currently using Linux Mint 15 but it would be quite easy to follow along on any other Debian based OS. Let’s get started shall we!

Brief Introduction
The OpenSceneGraph is an open source high performance 3D graphics toolkit. It is a real-time graphics middle-ware used by application developers in fields that range from visual simulation (flight, marine, vehicle, space simulator) to virtual and augmented reality, to medical and scientific visualisation, to education and games. Written entirely in Standard C++ and OpenGL it runs on all Windows platforms, OSX, GNU/Linux, IRIX, Solaris, HP-Ux, AIX and FreeBSD operating systems.

You can get more information at the official website: OpenSceneGraph

Downloading Source
You can download the openscenegraph source from one the following:

  1. Stable Release Section
  2. Code Repositories
  3. Developer Releases

Download the .zip file and extract its contents in OpenSceneGraph folder in your home.

Downloading the Dependencies
You need to download the necessary dependencies to be able to compile OpenSceneGraph.

  • Run the following command to download and install the necessary dependencies.

    apt-get build-dep openscenegraph

  • Or you can download .7z file from this page. And merge the files from this to the OpenSceneGraph folder in your home, for example, copy files from bin folder from .7z file to the bin folder in OpenSceneGraph folder. Do this for all the folders in .7z file.

The 2nd method is recommended for building.

CMake Tool
Make sure you have cmake tool installed on your system in order to compile OpenSceneGraph. If not, follow steps on their website.

Downloading the Data Resources
OpenSceneGraph standard dataset is required for use the with openscenegraph-examples. You can download it from this page.
Extract the contents of .zip file in the OpenSceneGraph-Data folder in your home.

Compiling
Now it’s time to compile. Run these commands in your terminal:

cd OpenSceneGraph
./configure
make
sudo make install

Running the Examples
Now our OpenSceneGraph has been built/compiled, its time to check it by running examples. But before we do that we need to place the location where it was installed on the system paths environmental variables. Edit your .bashrc file, add following lines in it:

export PATH=${PATH}:/home/myaccount/OpenSceneGraph/bin
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/myaccount/OpenSceneGraph/lib
export OSG_FILE_PATH=/home/myaccount/OpenSceneGraph-Data:/home/myaccount/OpenSceneGraph-Data/Images

Replace myaccount with your useraccount name.

Now we need to build the examples. Use following commands for building:

cd OpenSceneGraph
cmake -DBUILD_OSG_EXAMPLES=1

After the examples has been built you can run them, still in OpenSceneGraph folder, use following command:

sh ./runexamples.bat

Press Escape key to move to the next example.

That’s it! Enjoy OSG!

Connect to Wi-Fi Network through Ubuntu Terminal

Lot many people end up in a situation where they want to use internet while in console mode. It’s not that difficult task to connect to the Wi-Fi from the terminal.
There are some simple steps that you need to follow.

  1. Open the terminal.
  2. Type ifconfig wlan0 and press Enter. You will not see any output in the terminal, as this command just turns your wireless card on. Most wireless cards are designated wlan0. If yours has a different designation, use that instead.
  3. Type iwconfig wlan0 essid name key password and press Enter. Replace name with the actual network name, and replace password with the actual security key for the network. If your wireless network does not require a security key, do not enter key password.
    Note: If you want to type the ASCII password, you would use iwconfig wlan0 essid name key s:password.
  4. Type dhclient wlan0 and press Enter to obtain an IP address and connect to the WiFi network.

Enjoy!

Get LMMS on Ubuntu

Lmms_logo

LMMS is a free cross-platform software which allows you to produce music with your computer. A great DAW compose your own piece of music.
It covers creating melodies and beats, synthesizing and mixing sounds and arranging samples. You can have fun with your MIDI keyboard and much more – all in a user-friendly and modern interface. Furthermore LMMS comes with many ready-to-use instrument and effect plugins, presets and samples.

Downloading from Ubuntu Software Center:

  • Open your Ubuntu Software Center.
  • Search for LMMS in the search box.
  • Select the Linux MultiMedia Software(LMMS).
  • Click on Install option.

Compiling from source:

  • Download the source package from here.
  • Extract the file where you want to install LMMS.
  • Open your terminal and traverse(using ‘cd’ command) to the location where you extracted in the previous step.
  • Run the following commands:

sudo apt-get build-dep lmms
mkdir build
cd build
cmake ../
make
sudo make install

Note: Make sure you have latest cmake installed.

If even after installing the LMMS, you can’t find the menu item then do as following:

  • Create an new text file in home folder and name it ‘lmms.desktop’.
  • Run in terminal

gedit ~/lmms.desktop

  • Copy and paste the following content in the file and save it:

[Desktop Entry]
Name=Linux MultiMedia Studio
GenericName=music production suite
GenericName[ca]=Programari de producció musical
GenericName[de]=Software zur Musik-Produktion
Comment=easy music production for everyone!
Comment[ca]=Producció fàcil de música per a tothom!
Icon=/usr/share/lmms/themes/default/icon.png
Exec=/usr/bin/lmms
Terminal=false
Type=Application
Encoding=UTF-8
Categories=Application;AudioVideo;Qt
MimeType=application/x-lmms-project

  • cp ~/lmms.desktop ~/.local/share/applications/

Check out the documentation here.
Enjoy making music. \m/

Responsive Images using CSS

Its a short tutorial to make your images responsive in your website.

The HTML code would be as follows:

<img alt="" src="..your_im_path.." />

To make the image responsive lets enclose it a div with a class “img_wrapper”:

<div class="img_wrapper">
<img alt="" src="..your_im_path.." />
</div>

So now we will add our css to make it responsive:

.img_wrapper{
max-width:100% !important;
height:auto;
display:block;
}

This little code makes your image responsive!
Enjoy! ^_^

Enhancing your Vim in Ubuntu!

NOTE: This tutorial is for the people using Ubuntu 12.04 or above.

Hello and welcome to this tutorial for enhancing your favourite text editor Vim. ^_^
For those who don’t know what Vim is, check out its official website or this wikipedia page.

And those who are already familiar with it, lets advance to enhance. 😀
Lets see what we are going to do today. We will be updating our VIm with a plugn known as YouCompleteMe (YCM).

YouCompleteMe is a fast, as-you-type, fuzzy-search code completion engine for Vim. It has several completion engines: an identifier-based engine that works with every programming language, a semantic, Clang-based engine that provides native semantic code completion for C/C++/Objective-C/Objective-C++ (from now on referred to as “the C-family languages”), a Jedi-based completion engine for Python, an OmniSharp-based completion engine for C# and an omnifunc-based completer that uses data from Vim’s omnicomplete system to provide semantic completions for many other languages (Ruby, PHP etc.).
Source: http://valloric.github.io/YouCompleteMe/

Ok now moving on first we ensure that our Vim is compatible for this plugin.
Open your Vim, if not installed then you can skip this step, type
:version

If the version of the Vim is atleast 7.3.584 then its fine otherwise you may have to build it from source which is very easy to do.
So if you found out that your version of Vim is not upto-the-mark, then we have to remove it first before building it again.
Run the following commands in your terminal:
sudo apt-get remove vim vim-runtime gvim
and also
sudo apt-get remove vim-tiny vim-common vim-gui-common
These will remove the Vim installation from your system.

Now the next step is to build it from the source. Run these commands:
cd ~
hg clone https://code.google.com/p/vim/
cd vim
./configure --with-features=huge \
--enable-rubyinterp \
--enable-pythoninterp \
--enable-perlinterp \
--enable-gui=gtk2 --enable-cscope --prefix=/usr
make VIMRUNTIMEDIR=/usr/share/vim/vim74a
sudo make install

We have now successfully build the newer version of Vim on our system and now the next step is to install YCM plugin.
Type :echo has('python') in Vim. The output should be 1. This tells us that our Vim has Python support which is required for our plugin.

Now we will install YCm using Vundle. Its a Vim plugin manager.
To download Vundle run the following commands:
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
and then we must configure our bundles in .vimrc file. If you can’t find the file in your home folder then you may need to create it with following content:

set nocompatible ” be iMproved
filetype off ” required!

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

” let Vundle manage Vundle
” required!
Bundle ‘gmarik/vundle’

” My Bundles here:

” original repos on github
Bundle ‘tpope/vim-fugitive’
Bundle ‘Valloric/YouCompleteMe’
Bundle ‘Lokaltog/vim-easymotion’
Bundle ‘rstacruz/sparkup’, {‘rtp’: ‘vim/’}
Bundle ‘tpope/vim-rails.git’
” vim-scripts repos
Bundle ‘L9’
Bundle ‘FuzzyFinder’
” non github repos
Bundle ‘git://git.wincent.com/command-t.git’
” git repos on your local machine (ie. when working on your own plugin)
Bundle ‘file:///Users/gmarik/path/to/plugin’
” …

filetype plugin indent on ” required!

” Brief help
” :BundleList – list configured bundles
” :BundleInstall(!) – install(update) bundles
” :BundleSearch(!) foo – search(or refresh cache first) for foo
” :BundleClean(!) – confirm(or auto-approve) removal of unused bundles

” see :h vundle for more details or wiki for FAQ
” NOTE: comments after Bundle command are not allowed..

You can see that I’ve added a bundle for YCM too.
Now open your Vim and run
:BundleInstall

This will install all the bundles. 🙂

And we are done! ^_^
Enjoy!
Note:
If you get the ycm_core library not compiled error then you need to recompile it by following commands.
cd ~/.vim/bundle/YouCompleteMe
./install.sh --clang-completer

Also ensure that you have python headers installed if not then install by
sudo apt-get install python-dev

Creating Our First WordPress Plugin

So you finally decided to create your own plugin. But don’t know where to start?
Well in that case I can only say-

“Welcome Aboard’ 🙂

If you have searched on the Internet for plugin development, like I did, you would certainly be over-whelmed with so many tutorials and guides. And you can’t decide which one is better. Let me tell you, all of them are good and useful but certainly not the best. What?! Yes, you read that right. Nothing’s ever perfect, there’s always a need for improvement. Its the law of development.

Before you say anything, this tutorial falls in that same category. What I’ll teach you today is just the basic stuff to get you started in this field of WordPress plugin development.
Anyway, let’s begin with our tutorial. But first, let’s get the definition out of the way.

Plugin: In computing, a plug-in (or plugin) is a software component that adds a specific feature to an existing software application. When an application supports plug-ins, it enables customization.
(Source- Wikipedia)

To write a plugin for WordPress we must follow some guidelines that WordPress has provided. You can read about them here.
Ok! Here’s what we are going to do, we’ll create a plugin named ‘demo’ in this tutorial that will display the content ‘Hello! This is my first Plugin’ in any page or post that we want.

First let’s create a folder named ‘demo’ in our WordPress plugin directory. And then we create a file named ‘demo.php’ in it.
After creating it, we open that file in any text-editor and write the following code.

<?php
/* Plugin Name: demo
Plugin URI: http://demo.wordpress.com
Description: A demo plugin.
Version: 1.0
Author: Gurjot Singh
Author URI: https://bhattigurjot.wordpress.com
License: GPL2
*/
?>

We’ll save the file. You can write anything you want. But this information is very essential if we want our plugin to display in the Plugins section in our WordPress.

Now we can see our plugin listed among all other plugins. Yey! 🙂

Okay, moving on to the next part, we’ll create a simple HTML text in another PHP file.

We’ll now open a new document and write the following code:

<?php
function myfn() {
$html=' Hello! This is my first Plugin ';
}
?>

We’ll save this file as ‘function.php’ in our same demo directory.
We now have this function which contains html text but how do we display this text in our page?
To do this we must include this function.php file in our main ‘demo.php’ plugin file by adding the following code:

include ("function.php");

Even if we’ve included our ‘myfn()’ function in our demo.php we can’t display it as such. And we don’t even know where to display the text.

In order to do that we create a shortcode that we insert in any page or post to display our plugin’s content. To create our own shortcode we write the following in our demo.php file:

if ( !is_admin() )
add_shortcode('mydemo', 'myfn');

This creates a shortcode [mydemo] for our function myfn() that displays the text.
Now the complete demo.php file looks as follows:

<?php
/* Plugin Name: demo
Plugin URI: http://demo.wordpress.com
Description: A demo plugin.
Version: 1.0
Author: Gurjot Singh
Author URI: https://bhattigurjot.wordpress.com
License: GPL2
*/
include ("function.php");
if ( !is_admin() )
add_shortcode('mydemo', 'myfn');

?>

Ok so its time to activate our plugin.
After activating it we can insert our shortcode ‘[mydemo]’ in any page or post we want.

And now we’ll see our ‘Hello! This is my first Plugin’ text in that page or post.

That’s it Folks! We have successfully created our very own first plugin. CHEERS! 😀
If you are having some trouble then don’t hesitate to ask.
And do read WordPress codex for plugin development.
Writing a Plugin
Plugin API
Plugin Resources
These are very important.
Post your comments below and I’ll see you (text-ly) next time. 😛 Till then Keep Developing!