June 26, 2014

I was looking for a free api which can help me to get latitude/longitude on the basis of Postcode.

I tested pygeocoder and other api librearies which can help me, but none of them allowed me to query more than 25,000/day cause everyone is belongs to Google.

So I did an old school coding by using Mechanize and BeautifulSoup.
I used http://services.gisgraphy.com/public/geocoding.html. It's a free, I think they are providing 30,000 requests for demo user, I didn't tested 30,000 requests cause I've 29,000 records to generate lat/long. I don't want to waste my hits for a day. I'll test and update here.

Code is not clean, cause it's a test.

Keep Coding .


import mechanize
from bs4 import BeautifulSoup 

for x in xrange(30000):

    print '----------------- searching ---------------'
    br = mechanize.Browser()
    br.open("http://services.gisgraphy.com/public/geocoding.html")
    
    add = '81100'
    con='Malaysia'
    
    br.select_form(nr=0)
    
    br.form["address"] = add
    for i in range(0, len(br.find_control(type="checkbox").items)):
        br.find_control(type="checkbox").items[i].selected =True
    br.form["country"]=["MY"]
    
    print 'hitting --- ',x
    response = br.submit()
    soup = BeautifulSoup(response)
    
    
    links = soup.find_all('li')
    print '--------- getting list ----------'
    
    li = soup.find('div', {'class': 'summary'})
    
    print '---------- looking for latitude and longitude -------------'
    list= []
    children = li.findChildren()
    for child in children:
        list.append(str(child))

    print ' found latitude and longitude at point -->  ',x
    
    latitude = list[0]
    longitude = list[1]
    
    lat = latitude[9+5:len(latitude)-5].split()
    lng = longitude[9+6:len(longitude)-5].split()
    
    print str(lat).replace(',','.')
    print str(lng).replace(',','.')

#for f in br.forms():
#    print f



Source Code : https://bitbucket.org/ashish2py/quickhack/



June 19, 2014


December 03, 2013

I'm using crunchbang #! when it was #!-9 around in 2010 , now using #!-11. Between these period I tested out many linux distros but never feel that any linux is stable as #! is now, because it drops Ubuntu and using Debian-stable :) .
As per the heading of this post to change wallpaper in Crunchbang we need to copy paste the wallpapers( images ) into following directory./home/[username]/images/wallpapers/shared/
But "shared" folder is locked, so we need to copy-paste the images as a "sudo" user. Please Follow the steps.
1 Press "alt+f2" then enter "sudo thunar" and enter your password.
2 Now copy your wallpaper(images) and paste it into "/home/[username]/images/wallpapers/shared/" directory.
3 "Right-click" on the desktop and navigate to " settings > Choose Wallpaper ".
4 Now you can easily see the images and set the wallpaper by selecting images and clicking on "apply" button.

Here is my wallpaper link

Wait for the next crunchbang post. Keep Coding :)

August 07, 2013

I was configuring PPPOE connection manually by command line using "sudo pppoeconf", and by mistake I changed some settings. So after I restarted my laptop, I was getting an boot time error "waiting for network configuration" and after some time "waiting upto 60 seconds more for network configuration.."
Also there are possibilities to get this error while upgrading the system.
I solved these problem by using 2 methods.
After logged into Ubuntu.
Open terminal, type
First : not a permanent solution
  sudo /etc/init.d/network-manager start
Second : permanent solution
  sudo gedit /etc/network/interfaces
And remove the lines after
  auto eth0
  iface eth0 inet loopback
Make sure to save the file before closing it.Reboot the system

July 31, 2013


While I was making contact-us form in PHP for my client then I thought about to do same in Djago-Python. Target was to get the form input and email it. Here I'm going to test only the DjangoEmail module using shell.
Edit settings.py with code below:
    #settings for django email( writing for gmail)
    EMAIL_USE_TLS = True
    EMAIL_HOST = 'smtp.gmail.com'
    SITE_HOST = '127.0.0.1:8000'
    DEFAULT_FROM_EMAIL ='Dotorbit Team '
    EMAIL_PORT = 587
    EMAIL_HOST_USER = 'dotorbit.dev@gmail.com'
    EMAIL_HOST_PASSWORD = 'your-password'
    #Run interactive mode, 
    python manage.py shell
    #Import the EmailMessage module,
    >>>from django.core.mail import EmailMessage
    #Send the email,
    >>>email = EmailMessage('Subject goes here ', ' Body goes here ', to=['reciever@email.com'])
    >>>email.send()
    >>>1

This will return 1, means everything is working fine. form and view, I'll write in next post.

December 08, 2012


There are lots of tutorials available for Apache,MySql and PHP installation on linux and Windows. But I prefer the simple one for Debian.Command will not work without caret(^). sudo apt-get install lamp-server^ Now,This will download and install the Apache,PHP and MySql. step1 : test "localhost" in browser. Works !!
step2 : run the apache2 service. $ sudo service apache2 restart
or
$ sudo /etc/init.d/apache2 restart
If it works !! You are champ.
For me ,It throws an error --
codeleaf@dotorbit-backbox:/media/Development/Developer/HEROKU/DotOrbit$ sudo service apache2 restart
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
I googled about it and found the solution,
By default "httpd.conf" file will be blank. Now, simply add the following line to the file. $ sudo gedit /etc/apache2/httpd.conf Add the following line to "httpd.conf" and save it . ServerName localhost Now restart the server. $ sudo service apache2 restart
$ * Restarting web apache 2 server
... waiting
Woohoo.. It works
step3 - Test whether PHP is working or not ? Create "test.php" in /var/www/ directory. $ sudo gedit /var/www/test.php and add following line " < ?php phpinfo(); ? > step 4 - Test localhost/test.php and you will get the info page. e.g "PHP Version 5.3.10-1ubuntu3.4"

May 27, 2012


Before using Linux Mint Debiab Edition(LMDE) I was using Ubuntu-12.04LTS .
It was my worst experience with ubuntu. It looks like Ubuntu12.04LTS is not matured. I've faced lots of problems like touchpad freezes , after updates system get crashed , lots of bug reporting etc . Anyway I'm not anti-ubuntu .
In frustration I removed Ubuntu12.04 and installed LMDE on my Dell Vostro-1540 (core-i3).
Since the kernel is built with LMDE 201 109 486, then the default kernel is only able to detect a single core . Result was ,I've experienced some sort have 'hang' during my Android application development .
I decided to install the kernel 686, exactly 686-PAE. This kernel is the best solution for running LMDE on 'multi-core' system .
No need to worry about it .
Simple steps are here to install linux-kernel-i686.
 $ sudo apt-get update
 $ sudo apt-get install linux-image-686 linux-headers-686-pae
for i486.
 $ sudo apt-get update
 $ sudo apt-get install linux-image-486 linux-headers-486
for amd64.
 $ sudo apt-get update
 $ sudo apt-get install linux-image-amd64 linux-headers-amd64

May 22, 2012


Working on Blogger templates !! codesucksmybrain !! :)

April 29, 2012

Today morning around 4am , when I was designing my codeleaf blog site I just thought of tweeting something interesting but I dont wanted to tweet from the twitter Page. Instead, I wanted to tweet from terminal where I was doing other programming stuffs... So I decided to write a python-script to Post a tweet from my Terminal .
So I googled about "tweet from python" and I came across python-twitter and I started following Wiki for implementing that thing .
Steps that need to be followed are as follows ::
1. Register an Application on Twitter Dev-Center
Set your application's "Access level : Read, write, and direct messages "
Otherwise you will get an error for "Access level : Read Only"(TwitterError: Read-only application cannot POST.)

2. Copy your
 consumer_key = 'consumer_key',
 consumer_secret = 'consumer_secret',
 access_token_key = 'access_token_key',
 access_token_secret = 'access_token_secret'
and paste on some TextEditor ,because we will use this later .
3. Installation ( Python-Twitter )

Install the dependencies:
If your python-version > python2.7.2 , then skip first two library and directly install the third-one(python-oauth2) .
Download the latest python-twitter library from:
Extract the source distribution and run:
 $ python setup.py build
   $ python setup.py install
 

4 . create a python file and write the below code on it .

  
 import twitter
 api  = twitter.Api()

 #tweet
 def tweet(tweet_status):
  status = api.PostUpdate(tweet_status)
  print "Posted successfully"
  print status.text

 # OAuth authentication
 api = twitter.Api(
  consumer_key = 'consumer_key',
  consumer_secret = 'consumer_secret',
  access_token_key = 'access_token_key',
  access_token_secret = 'access_token_secret'
 )

 tweet_status = raw_input("Tweet Status : ")
 tweet(tweet_status)

5. Thats it . Now run the script , and Terminal(command prompt) will ask you to enter your "Tweet" .

 $ python pytweet.py 
   Tweet Status : I love Python-Twitter .
   Posted successfully
 Tweet Status : I love Python-Twitter .

April 18, 2012

Before using Heroku , I used Django-nonrel with Appengine , Django-Appengine , Google Appenigne , FluxFlex , Gondor hosting and Alwaysdata . From my knowledge I think Django-app deployment on Heroku is easier than others . When I was following official tutorial of django app deployment on Heroku , I got some errors so I googled and fixed all those errors . This is Heroku's official Documentation .Deploy Djang on heroku . Lets Start 
Install Heroku-toolbelt
wget -qO- https://toolbelt.heroku.com/install.sh | sh
1.Create folder called Heroku and move into it . $ mkdir Heroku && cd Heroku
2. Create a virtualenv and Activate your virtual environment
$ virtualenv --no-site-packages venv $ source venv/bin/activate This will change your prompt to include the project name. (You must source the virtualenv environment for each terminal session where you wish to run your app.)
3. Install dependencies with pip: $ pip install Django psycopg2 This step was failed for me , During Installation of "pip install psycopg" I got "Error: pg_config executable not found."
Linux User(debian based) : Make sure that u have "libpq-dev python-dev " packages installed . I used following command to install the above libraries $ sudo apt-get install libpq-dev python-dev for Windows User click here :
4.Great job ! Now Its time to create a Django app in the current directory: $ django-admin.py startproject greetingheroku .
5. Test the app runs locally by starting up the Django development webserver: $ python manage.py runserver
6. Create a pip requirements file which declares our required Python modules: $ pip freeze > requirements.txt All packages required should be declared explicitly in requirements.txt:
  $ nano requirements.txt
    Django==1.4
    psycopg2==2.4.5
now type ctrl+o(save) and ctrl+x(exit)
7. Commit to Git create .gitignore file and Exclude Virtualenv , because we don't want to push our local envirnment to heroku :
  $ nano .gitignore
    venv
    *.pyc
use ctrl+o(save) & ctrl+x(exit) . You will use Git to deploy code to Heroku
8. Initialize a Git repo and commit the project (if you aren’t already tracking your project with Git):
  $ git init
    Initialized empty Git repository in /home/ashish/developer/Heroku/greetingheroku/.git/
  $ git add .
  $ git commit -m "my django app" 
  $ heroku keys:add

9. Deploy to Heroku Create an app on the Cedar stack:
  $ heroku create --stack cedar
    Creating simple-spring-9999... done, stack is cedar
    http://simple-spring-9999.herokuapp.com/ | git@heroku.com:simple-spring-9999.git
    Git remote heroku added

10. Deploy your app: $ git push heroku master If "git push heroku master" gives you an error something like "heroku does not appear to be a git repository ." Then run the following command to add heroku as a git repository . Mostly this will happen , when u changed your app name from "Heroku dev center " $ git remote add heroku git@heroku.com:your-app-name.git
11. Check to see that your web process is up, to start $ heroku ps View your logs: $ heroku logs
12. finally visit your app on the web. $ heroku open
13. Syncing Database $ heroku run python manage.py syncdb 14. Using Django Shell $ heroku run python manage.py shell
For more information please visit > Deploy Djang on heroku .
My heroku app dotorbit.herokuapp.com
background