set java environment variables

export JAVA_HOME=/home/purandar/Downloads/jdk1.8.0_60
export JRE_HOME=$JAVA_HOME/jre
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

eclipse shortcut keys

  • Ctrl + _ for split horizontally, and
  • Ctrl + { for split vertically.

Git - get a single file

git archive --remote=git:// HEAD:path/to/directory filename | tar -x

1) path/to/directory should include the project name as well.
2) As of this post date archive supports only ssh url for the --remote  param, http will end with invalid protocol error.

VirtualBox - setup GuestAdditions

1) Install VB Extension Pack on Host Machine.
Check your VB version and download the corresponding version of extension pack from VB site.
Turn off all the VB Virtual Machines.
Go to VB > Preferences > Extensions (tab): select the downloaded extension pack and complete the installation.
Note: If you get any error here, most likely should be cause of version conflict.  The error message at last would also predict the same if read :)  So check your VB version and download the corresponding version of Extension Pack from the website,  like version 5 VirtualBox needs its equivalent version 5 Extension Pack.

2) Install GuestAddition (GA) tools on VM.
There are many ways to do this.  Some which I tried are
Method 1:
Attach Optical drive to the VM if a empty one is not present yet by going to Settings > Storage.  Have to turn off the VM to attach.
Turn ON the VM and go to the menu bar > Device > Install Guest Addtions.
This should mount the GA iso to the VM which should show the disc icon on Desktop.  Mount this, open the folder and run the file corresponding to your VM OS.  For Ubuntu/Linux based machine I ran file.
Instead of mounting from VM, one could also run wget to download the same iso image and later mount it then proceed with install/running the script.

reboot now.
Method 2:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install dkms

sudo apt-get install virtualbox-guest-dkms

Troubleshooting: I faced some header error something when I ran the script for which I run
sudo apt-get install linux-generic
sudo apt-get install linux-headers-$(uname -r)

Verify if GuestAddition tools are setup correctly.
vagrant@vagrant-ubuntu-trusty-64:~$ lsmod | grep -io vboxguest
vagrant@vagrant-ubuntu-trusty-64:~$ modinfo vboxguest
filename:       /lib/modules/3.13.0-62-generic/updates/dkms/vboxguest.ko
version:        5.0.0
license:        GPL
description:    Oracle VM VirtualBox Guest Additions for Linux Module
author:         Oracle Corporation
srcversion:     BD84A3E9EE7A3DA047005F9
alias:          pci:v000080EEd0000CAFEsv00000000sd00000000bc*sc*i*

vermagic:       3.13.0-62-generic SMP mod_unload modversions

Python django

Install python
Install python setup tools - sudo curl -o - | python
Install virtualenv - sudo easy_install virtualenv
Initialize virtualenv - virtualenv --no-site-packages django-purandar
Install django - 
  • cd django-purandar/
  • easy_install django
  • cd bin
Create Project
  • django-admin startproject django-test
  • python runserver
  • access server at
  • deactivate
  • source bin/activate
  • cd django-test
  • vim
  • edit - DATABASES, ENGINE: add sqlite3, Name: path for storage.db file
create app - 
python startapp <appname>
This will create base files for the app.,, and - just mentions that this folder is a package/module so that this can be imported to other programs. - for db related information like
class Article(models.Model):
  title = models.CharField(max_length=200)
  body = models.TextField()
  pub_date = models.DateTimeField('date published')

  likes = models.IntegerField()

Now tell django to create the respective DB from
python syncdb
This will create the tables and create the db file in the respective path provided in earlier.
Browse the DB file using "sqlite browser" 
Notice that no <app> related table is created there, that is cause we haven't added our application to the file.
python makemigrations
python migrate
python syncdb

FYI: below command can be run to obtain actual sql query to run in DB
python sql <appname>

Due to version conflict If: CommandError: App 'article' has migrations. Only the sqlmigrate and sqlflush commands can be used when an app has migrations.
Delete or rename the migrations folder within the <app> dir structure.
python sql <appname>

If any model definition is changed, then try python reset <appname> - careful this will remove all of data in DB

Importing/Adding data to app DB, by running Shell
python shell
>> from <appname>.models import <ModelName>
>> <ModelName>.objects.all()
Displays all objects in DB.
To insert data
>> var = <ModelName>(key=value, key=value,...)
>> <ModelName>.objects.all()

To get the correct ID to be displayed.  Define __unicode__(self) function in
>> from <appname>.models import <ModelName>
>> <ModelName>.objects.all()
Should now display what ever is returned in unicode function.
  def __unicode__(self):
    return self.<key>

1) Views
Create view - <app> folder
def hello(request):
  name = "Purandar"
  html = "<html><body>Hi %s, this seems to have worked!</body></html>"%name

  return HttpResponse(html)
assign url - <project_test> folder

url(r'^hello/$', '<appName>.views.hello'),

2) Templates View
Define html templates in a folder and define the path in <Project_test>/
'DIRS': ['/Users/purandarkakde/python/django-purandar/django_test/templates'],
Define hello.html in templates folder

Hi {{ name }},
this TEMPLATE seems to have worked!

Import the templates in <appName>/
from django.template.loader import get_template

from django.template import Context
def hello_template(request):
  name = "Purandar"
  t = get_template('hello.html')
  html = t.render(Context({'name': name}))
  return HttpResponse(html)

Add the url in <Project_test>/
url(r'^hello_template/$', 'article.views.hello_template'),
Runserver and Access:

3) Class View
Add view definition in <appName>/ file

from django.views.generic.base import TemplateView

class HelloTemplate(TemplateView):
  template_name = 'hello_class.html'

  def get_context_data(self, **kwargs):
    context = super(HelloTemplate, self).get_context_data(**kwargs)
    context['name'] = "Purandar"

    return context

Define the URL
url(r'^hello_class_view/$', HelloTemplate.as_view()),

Define <hello_class.html> New Template in Templates folder.

4) Render Template method
from django.shortcuts import render_to_response
def hello_template_simple(request):
  name = "Purandar"
  return render_to_response('hello.html', {'name':name})

Define its url in <projectName>/

non root user login setup for Docker

Create docker Group, add user to group, restart docker service, login as docker.

sudo groupadd docker
gpasswd -a ${USER} docker
sudo service docker restart
sudo service restart
newgrp docker

Mac restart sshd service

services (sshd for example) are disabled in the configuration file so you will need to use the '-w'switch when loading them. Here is a sshd example:

Start the service
   $sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist 

You can stop the service using the 'unload' subcommand.
   $sudo launchctl unload  /System/Library/LaunchDaemons/ssh.plist 
To list the services, use the 'list' subcommand