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=”https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places”></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();
alert(place.formatted_address);
You can find a demo here: Google Address Auto Complete DemoIn 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.

DJango Python 101

DJango commands cheatsheet

How to start server:

./manage.py runserver


How to create new app

./manage.py startapp newappname

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

./manage.py syncdb

How to use South
http://south.readthedocs.org/en/latest/commands.html

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

./manage.py convert_to_south myappname

For new apps
Create db (Similar to syncdb command)

./manage.py schemamigration myappname –initial

Update db with schema changes

./manage.py schemamigration myappname –auto

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

./manage.py migrate myappname

PSQL 101

How to create a database
CREATE DATABASE mydatabase;

How to create a user

CREATE USER priyank with password ‘passw0rd’;

How to grant access to a user

GRANT ALL PRIVILEGES ON DATABASE mydatabase to priyank

How to see list of databases

psql -l -U priyank

Alternatively you can connect to database first and then type ‘l’

l

How to see list of tables

#Connect to database first.
d

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.


#!/bin/sh
i=0
j=5
while [ $i -le $j ]
do
i=`expr $i + 1`
echo $i
done

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.

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.

e.g.

curl -x 127.0.0.1:8888 http://www.priyankgandhi.com

If your url is https, then you will need to pass -k parameter. This will disable curl’s ssl verification.
curl -k -x 127.0.0.1:8888 https://www.google.com

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.

hostname:port:database:username:password

priyank@localhost:~$ vi .pgpass
192.168.1.101:5432:restaurant:priyank:passwordispassword

Here is a documentation from postgresql site.
http://www.postgresql.org/docs/9.1/static/libpq-pgpass.html

XAMPP: How to change default language for phpmyadmin

Today I installed XAMPP. After installing, First thing I wanted to do was change mysql password. After searching on xampp site, I found out I can change mysql password using phpMyAdmin. (Ref: link) When I went to phpMyAdmin, everything was in German. After some search, I found out that you have to add two lines in config file.

C:xamppphpMyAdminconfig.inc.php

In this file add following line.

$cfg[‘DefaultLang’] = ‘en-utf-8’;

After this just reload phpmyadmin page.

Cygwin: rebaseall utility

You may sometimes see cygwin error like this.

bash 4944 exception::handle: Exception: STATUS_ACCESS_VIOLATION
emap to same address as parent

Short answer

To fix these errors, run these commands from your MS-DOS command prompt.

cd cygwinbin
ash
PATH=. rebaseall -v

More Details

Rebaseall utility
Rebaseall utility should be available under /cygwin/bin/ directory.
To check if rebaseall is available or not. If it is available it will print something like this.

priyank@~:>which rebaseall
/usr/bin/rebaseall

Only ash process is allowed to run rebaseall. Means you cannot run rebaseall directly from cygwin.
Open MS-DOS command prompt and follow these steps to to run rebaseall.

cd cygwinbin
ash
PATH=. rebaseall -v