Monday, December 22, 2014

Install django in virtual environment

# Pre req:

I am using ubuntu 10.10 for this tutorial. Setup environment for python

# Install Django:
   Run below commands to setup django and create my first app

  pip install django

# Create test project startproject testsite

It will create the testsite as project. Each project consist of many sub projects call apps. Lets create a app and call it soapapp, Which will take input soap requests. and will response json. I will write a blog on it latter on.

python startapp soapapp

Use terminal and write these command
>> ls
you will see component if django app like views, models, tests with (py) extensions, ofcourse it is python project

So in views. py we will create a view. A simple code that will response ok is attached

import json
from django.http import HttpResponse

def hello(request):
    response_data = {}
    response_data['result'] = '200'
    response_data['message'] = 'ok'
    return HttpResponse(json.dumps(response_data), content_type="application/json")

Lets create urls class, where we will register url for above create view.

from django.conf.urls import patterns, url
from views import *

urlpatterns = patterns('soapapp.views',
   url(r'^hello$', 'hello', name='hello'),

Register this url file in main app
so from command line open

/venv_hello/testsite/testsite$ sudo gedit &
And append this line in url

url(r'^soap/', include('soapapp.urls')),

Run app:

To run this app open email folder, root of the app, as we have testsite. There type command
sudo python runserver
you can see reponse

You can download sample project from this link.



Setup environment for python

Pre req:

I am using ubuntu 10.10 for this tutorial.

1) Install python

Using below command you can install python, I will install components like pip, virtualenv along with python.

Open terminal and past below code:

sudo apt-get install python-pip python-dev build-essential

# Check version of python
python --version

# Upgrade tools:
sudo pip install --upgrade pip
sudo pip install --upgrade virtualenv 

2) Create a virtual environment and setup project

#Create a folder 

mkdir pywork
cd pywork
mkdir hellopy
cd  hellopy

# Create virtual environment for this project. 
virtualenv venv_hello (you can use any name)
cd venv_hello 

3) Create and execute a file (py)

  Create a file lest say You can add code like
   def test():
     print("Hello python")
to execute file use command  in terminal




Monday, December 15, 2014

Setup environment for extension for my SmartWatch 2

In this blog I will demonstrate how to set up environment for development of apps for SW2.
I purchase SW2 because of its benefits written below

 # Now I can set my mobile on silence mod in office. When any call comes SW2 notify me.

# I have 5 inc mobile. Now I dont need to pick up every time I gets any notification. I just use my watch to see if the notification is important for me i.e I wana reply only then I pick phone. It saves time for me ... as I am a busy guy :)

# I can take selfy by adjusting my mobile on some place and with the help of  SW2 I can capture picture.

# There are holes in software of this device, there are great opportunities to build software for it

So let us make this watch more useful

Pre req:

Before start you must have installed android SDKeclipseADT.
Set up you SW 2 (Smart watch 2).

Step 1 Install Sony SDK:

# Open Android sdk manager, Select tools ->  Ad on sites. And select user defined sites.

# Click new button and insert => in text box. click OK and close.

You can see a package name Sony Add-on SDK under Android 4.2.2 (API 19) and a package  Sony Add-on SDK in packages -> extras. Install this package.

#    Now after installation open File -> Import ->  Existing Android Code Into Workspace -> your android SDK/add-ons\addon-sony_add-on_sdk_3_0-sony-19\samples\SmartExtensions

Import projects in this folder. If you find any dependency issue. Right click each project and go to Properties -> Android -> Android target project and make it 4.4.2. After doing this to all clean and build workspace.

Step 2 Run a project on smartwatch 2:

# Now run a sample project. Lets say HelloActiveLowPowerPreferenceActivity. If your SW2 is connected with phone you can see below app, On Clicking text counters increment .