Saturday, January 19, 2013

Google Address AutoComplete Tutorial

This is very basic for google address lookup/auto completion tutorial.
First thing you need to do is include google maps javascript to your page.

<script src=""></script>

Next step is to initialize Autocomplete. When you initialize Autocomplete, it basically starts a listener which listens for an input. Following code does that.

var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);

When you start typeing it looks like this.

When user selects an address, value of input field get updated to selected address. You do not need to have nay extra code. However in case if you want to read selected address, you will need to add "place_changed" google maps event listener. It returns PlaceResult object. Following code shows how you can get PlaceResult object.

google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();

You can find a demo here: Google Address Auto Complete Demo In this example, I am loading address lookup form using an ajax.

You can download demo source from github: View source code

Here is the complete snippet.

Wednesday, January 2, 2013

PSQL: find current database, schema, user

SELECT current_database();
SELECT current_schema();
SELECT current_user();
More commands like this, you can find it here.

Friday, December 14, 2012

DJango Python 101

DJango commands cheatsheet

How to start server:
./ runserver

How to create new app
./ startapp newappname

Database stuff
How to create database from models (Use South instead)
./ syncdb

How to use South

For existing app
you will need to convert into South supported app first.
./ convert_to_south myappname

For new apps
Create db (Similar to syncdb command)
./ schemamigration myappname --initial

Update db with schema changes
./ schemamigration myappname --auto

These commands generates migration scripts only.
Run this command for changes to take effect in db
./ migrate myappname

Sunday, November 18, 2012

PSQL 101

How to create a database

How to create a user
CREATE USER priyank with password 'passw0rd';

How to grant access to a user

How to see list of databases
psql -l -U priyank
Alternatively you can connect to database first and then type '\l'

How to see list of tables
#Connect to database first.

Friday, November 9, 2012

Shell: How to increment a value in a shell script

This is a very basic question that comes into our mind many times while writing a shell script.

Here is a small code that you may find it useful.

while [ $i -le $j ]
i=`expr $i + 1`
echo $i

Here I am using expr unix command. This command evaluates arguments as expressions. You can find more details about expr by typing man expr in your terminal or check this link for online manual.

Tuesday, August 28, 2012

Monitor cURL traffic in fiddler

If you want to view your curl request-response in fiddler, you need to tell curl to use fiddler proxy.
You can do that by passing -x parameter.
curl -x

If your url is https, then you will need to pass -k parameter. This will disable curl's ssl verification.
curl -k -x

Tuesday, August 21, 2012

PostgreSQL: login without entering password

If you want to connect to your postgre database without entering password every time, you can achieve that by creating PGPASS file in your home directory.
e.g. Create a file called .pgpass in your home directory. Add and entry in this format.


priyank@localhost:~$ vi .pgpass

Here is a documentation from postgresql site.