Monday, September 24, 2012

Quick Setup CherryPy in Python 3

CherryPy is a minimalist, pythonic, object-oriented HTTP framework.
For Windows,
1. Download and install the latest version of python 3.
2. Download and install the latest version of CherryPy with wsgiserver3 support.
3. Test the installation by running an example program (say hello.py) like below.
import cherrypy

class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True

cherrypy.quickstart(HelloWorld())
4. Navigate to the directory and run python hello.py to start the server.
5. Now goto 127.0.0.1:8080 and we will get a "Hello World!" from the server.

Thursday, September 20, 2012

Generete Ant build.xml for an Android Project

If we have an Android project which does not have a build.xml, then we can generate a build script by running the below command.
1. Navigate the android project root directory
2. Update the project to generate the build file
android update -p .

Thursday, September 13, 2012

Common Regular Expressions

Match letters, space, comma, ampersand, hyphen, forward slash, parentheses with length 1..12.
^[a-zA-Z0-9\s,&-/\(\)]{1,12}$
Match 2, 3 digit numbers with 0 to 2 decimal places.
[1-9]{2,3}(\.\d{1,2})?
Matches everything including control characters with length 5..255.
^[\w\d\s\W]{5,255}$
Postal code with min length 3, max length 10. Upper case alphabets, digits and spaces.
^[A-Z0-9\s]{3,10}$
Mobile number with length 10..15 with an optional plus '+' symbol in front.
^\+?[0-9]{10,15}$
Number with minimum 2 digit with first digit not zero and max 3 digit number, with optional decimal upto 2 place.
^[1-9]{1}\d{1,2}(\.\d{1,2})?$

Sunday, September 9, 2012

Install GCC in Nokia N900

The GNU Compiler Collection (GCC) can be installed in Maemo on Nokia N900, which allows on device development! To install them, first add the Maemo SDK repository to the application catalogs. Do *not* run upgrade (apt-get upgrade) after enabling the SDK repository. After the installation of the build tools, disable the SDK repository. Once the repo is disabled we can run apt-get upgrade command safely.
Catalog name: maemo sdk
Web address: http://repository.maemo.org
Distribution: fremantle/sdk
Components: free non-free
After reloading, close the application manager.
In the terminal, run the following.
root
apt-get update
apt-get install build-essential #installs the necessary packages
exit
Open the application manager and disable the SDK repository. After that run update.
apt-get update

Thursday, September 6, 2012

Writing Bash Shell Logs With Date & Time

Bash shell scripts can be used to do a variety of things. It is very easy to schedule the script to run under crontab. It would be helpful if we log the steps with date time and a message. It can be done as follows.
echo '['`date +%F\ %T`'] Downloading file abc'
#outputs: [2012-09-06 23:20:16] Downloading file abc
NB: The date command is enclosed in back tick, not single quote.