Using Ubuntu cloud images in KVM

By : Thejaswi Puthraya

Quite a few of our clients are powered by Amazon EC2 or Rackspace and we use Ubuntu LTS releases for our servers. Canonical provides EC2 AMIs and Openstack images for all their releases. By using these JeOS images on the server as well as on the development platform reduces the dev/prod parity which we discussed in a previous post.

In this post, we'll see how to setup the Ubuntu cloud images in the local KVM hypervisor. Unlike the previous post, we'll use only the virt-manager to do the initial provisioning but you can be assured that there ...

more info..

Metaclass in Python

By : Akshar Raaj

In this post we will be talking about Metaclass in python. If you are reading some code which uses metaclass, you will probably come across __new__. If you are not familiar with what __new__ does, i suggest you first read about __new__.

You can read about __new__ in our last to last post

Throughout this post we will be talking about new style classes. Things might differ in old-style classes.

As we go, i will be trying everything on IPython and suggest you as well to try everything on IPython.

Let's see a little bit about normal Objects in ...

more info..

Libvirt and KVM

By : Thejaswi Puthraya

"But it works on my local setup!" We have heard or probably said this tens of times after something that we deployed to the production server breaks. After fire fighting for hours we learn that a particular package's version varies from the local setup. This is a fairly common problem that plagues every developer. Off late, quite a lot of interest and work is going into maximizing the dev/prod parity to prevent such problems.

Software like virtualenv help a great deal in compartmentalizing python dependencies but most web applications nowadays have to deal with loads of other dependencies ...

more info..

__new__() in python

By : Akshar Raaj

Lately I started looking into Django code and wish to write about internals of Django. I started with Django models and will be writing about it soon. For understanding how Django models work, I had to understand what metaclasses are and how metaclasses work. Metaclasses use method "__new__" and so I looked at what "__new__" does.

As __new__ is a static method, we will see a lttle bit about static methods and then __new__ in detail.

  1. Understanding static methods.

  2. Understanding method "__new__" of any class. We will see how to override method __new__ in a class.

Also, I will be ...

more info..

Understanding '*', '*args', '**' and '**kwargs'

By : Akshar Raaj

When i started learning Python, i was very confused regarding what args, kwargs, * and ** does. And i feel there are few like me who had this confusion and problem. With this post, i intend to reduce (hopefully i can eliminate) that confusion.

Throughout this post, i will be using ipython and i suggest you to try everything on ipython as well. We will intentionally make some mistakes along the way, so that we can understand this topic better.

Let's divide our work under five sections:

  1. Understanding what '*' does from inside a function call.
  2. Understanding what '*args' mean inside a ...

more info..
Topics : python args kwargs

Provisioning Made Easy With Chef

By : Saket Bhushan

Managing Servers and scaling at will is hard. The bigger web players have put in years of effort, brute-forcing at times and re-iterating their methodologies, have come up with the secret sauce which they use to keep their cloud cool. The article is meant to be introductory rather than comprehensive. Chef has a steep learning curve, and in this post I wish to simplify few of the basic concepts. So, instead of going to the Chef Docs, finding searching, reading and re-reading, few of the beginner concepts are put at one place, which will help you get started on your ...

more info..

Test Driven Development in Python

By : Anoop Thomas Mathew

We can either prevent bad things from happening or fix it, once it is detected.

It is your choice to select any of these methodology, while developing a software. You can either develop based on a test driven process or the recover from a fiasco with tests.

Test driven development, as the name suggests, is development based on tests. Tests for core features are written prior to the implementation for the expected output, and then necessary modules are written to satisfy the needs define the


Advantages of Test Driven Development

  • application is determined by using it
  • written minimal amount of ...

more info..

Deploying Django apps on Heroku

By : Shabda Raaj

Deploying Django apps on Heroku:

Read this first: http://devcenter.heroku.com/articles/django.

This is a great article by the Heroku. I am just filling in some more details and making this step-by-step.

  1. Get your Django project code.
  2. Create a virtualenv with a no-site-packages command ::

    virtualenv vent --no-site-packages

  3. Install Django, psycopg2 (postgres connector), gunicorn and any other required Django libraries.

  4. Confirm that you have all the required libraries and you can run your code locally using manage.py runserver.
  5. Create a requirement.txt by using ::

    pip freeze > requirements.txt
    
  6. Make sure you have a requirements.txt at the root ...

more info..
Topics : django

Developing android applications from command line

By : Thejaswi Puthraya

Here at Agiliq, we also develop cross-platform HTML5 mobile applications. Using Eclipse to create an android project (one time task) and edit html and javascript files for an android app is an overkill. Wouldn't it be great, if you could use your favourite text editor to edit html and js files and then fall back to the terminal to deploy the android app? We are going to see exactly this in the post.

First, let's install the android SDK starter package(I assume that you have installed JDK and ant). Head over here and install the SDK for ...

more info..

Deploy Django App in 5 Easy Steps

By : Saket Bhushan

So you just bought a new VPS, have installed Ubuntu and want to deploy your django app, GREAT!! We shall get your app, up and running in 5 easy steps, using best(arguably) of tools available. The post is targeted to audience who are new to deployment arena, but assumes you are comfortable with developing basic django apps. We shall be using gunicorn as our server and nginx nginx as our reverse proxy and static hanlder. Here we go:

1. Login and OS Updation:

$ ssh root@{your_ip}

# apt-get update

# apt-get upgrade

# apt-get dist-upgrade

# dpkg-reconfigure tzdata #choose your time zone

2 ...

more info..

Project Management Tools for Start-Ups

By : Anoop Thomas Mathew

An integral part in the success or failure, of any company is the management and communication between peers within the company as well as a well formed communication with the clients itself. 1990s was marked with the rise of tools like bugzilla, trac and a few other, which allowed developers to develop collaboratively, and more over, a bit more organized with the ticketing system. One thing to be noted is that, they did what they were supposed to do, and they still do.

As the time pass by, we got a huge number of code hosting, along with project management ...

more info..

Generating a pdf from an image using PIL and django

By : Saket Bhushan

In this post we shall be performing small image manipulation on the server side and allowing the user to download the pdf. This might be found useful if you design a quiz app and want to generate a certificate for the users. The various methods which can be followed to generate the certificate are:

  1. Have an image file to serve as a template, use css to place the username at the desired location.
  2. Have a pdf file, which can be edited to take the username of the current user if he has passed certain test.
  3. Have an image template ready ...

more info..

Dynamically attaching SITE_ID to Django Caching

By : Anoop Thomas Mathew

It would be useful and convenient, if you have an automatic way to add the SITE_ID, especially, when you have multiple sites running on the same deployment. Django provides a cache prefix function KEY_FUNCTION in settings which can be used to achieve this.

Just follow the following steps, and your cache, automatically prepends SITE_ID to the cache key, making it unique across multiple sites.

  1. Put the following into the settings file.

         CACHES = {
    
         'default': {
    
          'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
    
           'LOCATION': 'cache_table',
    
           KEY_FUNCTION = projectname.appname.modulename.functionname,
    
                    }
    
             }
    
  2. Write a function to get current site id, say, get_current_site(), which returns current ...

more info..

Deploying Django apps on Heroku

By : Shabda Raaj

Read this first: http://devcenter.heroku.com/articles/django.

This is a great article by the Heroku. I am just filling in some more details and making this step-by-step.

  1. Get your Django project code.

  2. Create a virtualenv with a no-site-packages command

    virtualenv vent --no-site-packages
    
  3. Install Django, psycopg2 (postgres connector), gunicorn and any other required Django libraries.

  4. Confirm that you have all the required libraries and you can run your code locally using manage.py runserver.

  5. Create a requirement.txt by using
    pip freeze > requirements.txt
    
  6. Make sure you have a requirements.txt at the root of your repo. Heroku uses ...

more info..
Topics : django

Getting started with South for Django DB migrations

By : Akshar Raaj

South is a migration tool used with Django.There will be times when you would be adding fields to a model or changing the type of field (eg: Field was an IntegerField and you want to change it to FloatField). In such cases syncdb doesn't help and South comes to your rescue.

There were times when i tried "python manage.py migrate southapp", got some error and then tried "python manage.py migrate southapp 0001 --fake". In some cases, that worked. When it did not work, i tried something else and so on. There were confusions regarding what --fake ...

more info..
Topics : django South south

A brief overview of Vagrant

By : Dheeraj Sayala

Vagrant is a very good wrapper around Oracle's VirtualBox. It makes life easier for web developers and the like by providing a nice command-line interface to build, manage, provision, use virtual machines.

Why should you use Vagrant?

  • You may want to install different versions of software without worrying about conflicts
  • You don't want to remember which services to start/stop when you start working on a project
  • The version of Operating system you use can be different from the one on the server. So, you want a way to emulate the behavior on server
  • You want to develop ...

more info..

Writing jQuery plugins using Coffeescript

By : Shabda Raaj

So you want to write a Jquery plugin. If you know jQuery and Coffeescript, this would be amazingly easy.

I will walk you through writing a jQuery plugin which will allow us to add alternating colors to alternating rows.

Here is the plugin in its entirety.

$ = jQuery
$.fn.zebraTable = (options) ->
    defaults = 
        evenColor: '#ccc'
        oddColor : '#eee'

    options = $.extend(defaults, options)
    @each ->
        $("tr:even", this).css('background-color', options.evenColor)
        $("tr:odd" , this).css('background-color', options.oddColor)

Lets look at what we did.

  1. We bound $ to jQuery object.
  2. We created an anonymous functions and added this to jQuery, by assigning it to $.fn ...

more info..
Topics : coffeescript

Behind the Scenes: Request to Response

By : Thejaswi Puthraya

In the previous installment of "Behind the Scenes", we saw how the control flows from Form to File Storage. Today, we are going to see how the application reacts from request to response.

In this post, we are going to assume that we are using django's inbuilt runserver. The flow doesn't change much for other WSGI servers available.

When you invoke the runserver management command, the command line options are validated and an instance of WSGIServer is created and passed the WSGIRequestHandler, which is used to create the request object (WSGIRequest). After the request object is created and ...

more info..

Using SQLite Database with Android

By : Bala Subrahmanyam Varanasi - Where there's a will, there's a way.

Android embeds an Open Source Database called SQLite, which supports standard relational database features like SQL syntax, transactions and prepared statements. In addition it requires only little memory at runtime (approx. 250 KB). In this post I would like to show how to work with a simple pragmatic example : Baby Names App.

Before writing the code, let me show you some of the screen-shots of Baby Names App, which requires interaction with the database.

  1. When ever you launch the App, it will shows a Menu of items as below. Baby Names App Menu

  2. When we click on the highlighted button - "Common Names", it will ...

more info..
Topics : android java

Haml for Django developers

By : Shabda Raaj

Haml is taking the Ruby(and Rails) world by storm. Its not used as heavily by Python(and Django) developers as the Python solutions aren't as mature. I finally gave Haml a try and was pleasantly surprised how easy it was.

The most mature Python implementation of Haml is hamlpy, which converts the hamlpy code to Django templates. Others are shpaml and GHRML

Lets look at some templates from Django tutorial

{% if latest_poll_list %}
    <ul>
    {% for poll in latest_poll_list %}
        <li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li>
    {% endfor %}
    </ul>
{% endif %}

Here is this template converted to Haml

-if ...

more info..
Topics : django

Coffeescript for Python programmers

By : Shabda Raaj

I just learnt Coffeescript, and as a Python programmer loved being able to write Javascript in a Python like language. Coffeescript is inspired by Python/Ruby and is very close to these languages. Writing Coffeescript and reading the compiled Javascript also improved my understanding of Javascript. Without much ado here is translation of some Python code to Coffeescript to get you started.

Defining a variable

Python
a = 10

Coffeescript
a = 10

Setting scope is done via whitespaces.

Python

if i == 10:
    foo()

Coffeescript

if i == 10
    foo()

No semicolons

List comprehensions

Python

languages = ["Python", "Coffeescript", "Java", "Ruby", "Haskell"]
languages = [lan ...

more info..
Topics : coffeescript
© Agiliq, 2009-2012