Friday, May 1, 2009

Will the history repeat itself, with Grabbler?


Word games have been around the corner for quite some time now. Some give clues to guess the word, some give letters to make maximum possible words. Each one trying out a different strategy but to obtain a simple objective - form words. I remember to have played a few word games during my childhood days Scrabble, Word Crosswords being the notable ones. Well, times change, paper-pen games are remnants of the bygone days and now its an era of games on Facebook.

On and off, I had been playing Scrabble on Facebook, until i found Grabbler. It is a multi-player game which tests your word making skills, with its unique cubes. Err...on second thoughts, not so unique cubes. Actually, the possiblity that you would get the same cube again in a game is 144 in 26!/20! i.e. 1 in 1,151,150. Hence, the not so unique cubes. Over the last 45 days I have been hooked on to the game. I think I have even played a few moves in my sleep. And, tonight, I have decided I will stop playing it, at least for a few weeks. I would like to catch up more sleep in the coming few days. This decision has come after a lot of deliberations. The addict wanting to sniff more and the reasonable self in me wanting to shun it.

But, this does not stop me from appreciating the game. After a long time, a game caught my imagination. The game has a pleasant interface and has the right combination of skill and luck. It is well matched with a test of patience too. It has been fun, having beaten some very good players and remaining invincible. The eye catching feeds have been such a delight to post on the profile. Although, the game has been introduced very recently, I think this game will definitely climb the ladder pretty fast. Moreover, it is a good change for some one bored by the age old Scrabble.

That reminds me of the fact that Scrabble was created by Alfred Mosher Butts during the Great Depression in the 1930s and the game went on to occupy space in every other household. Almost eight decades later, the world is going through another major economic slowdown and Grabbler has been created. Will the history repeat itself?

Well that remains to be seen, but for now, it is adios Grabbler,for me.

Saturday, March 7, 2009

How I set up my Turbogears based development environment...

The start of 2009 brought along a new project for me. It was based on Turbogears 1.0.4.4 with Postgresql 8.3 as the database. Here is a list of steps I followed to setup my development environment.

1. Installed Python 2.4.4.

2. I was working on a windows platform and required support for it so I installed extensions for windows. PyWin32 is a collection of modules for advanced windows-specific support. These include utilities for COM, Win32 API calls, Registry, Event Log and MFC user interfaces.

3. Installed setuptools, so as to be able to build and distribute packages. It includes a utility easy_install, which lets you automatically download, build, install, and manage Python packages and their dependencies.

4. Installed the Turbogears web application framework by running the command:

>easy_install-2.4 -f http://files.turbogears.org/ "TurboGears==1.0.4.4"

5. Installed win-psycopg, a windows port of the psycopg python-postgresql database interface.

6. Installed SQLObject, an Object Relational Manager which provides an object interface to your database, with tables as classes, rows as instances, and columns as attributes. Used the following command to install it:

>easy_install-2.4 "SQLObject==0.10.2"

7. Installed other packages like PyPDF 1.9, ElementTree 1.2.6, ElementTidy and PyLucene for my text based application.

8. Installed TinyMCE 1.0.6, a JavaScript HTML WYSIWYG editor control, using the following command:

>easy_install-2.4 "TurboTinyMCE==1.0.6"

9. Downloaded the ExtJS 2.2 Library. It has some excellent built-in components ready to use.

10. Installed Eclipse 3.2 IDE and added the PyDev plugin using the manual and configured it accordingly.

There I was, ready to play!

Friday, March 6, 2009

Remote access to PostgreSQL Server

Error: "could not connect to Server: Connection refused"

The resolution is a five step process : -

1. Firstly, check if your firewall allows the port (default is 5432) to establish a connection.

2. By default, PostgreSQL does not allow remote incoming connections. This has been implemented in this way, because of security concerns. You need to enable incoming TCP/IP connection requests from the client. This can be done by adding

#
listen_addresses = '*'
#

in the configuration file postgresql.conf. This configuration is valid for postgresql 8.x.

3. You will have to inform Postgresql who can connect to the server. This has to be done by modifying the configuration file pg_hba.conf

host all all 127.0.0.1/32 trust
host all all 192.168.0.0/16 trust

This would allow any user on the local network to access all the databases on the server in "trust" mode.

4. After you have saved the configuration files you will have to restart the server. Remember, these configuration files are read on server startup.

5. Test your config. Go to the command prompt and run the following command.


>psql -h serverIP -U postgresUser -d postgresdb


And, you should be set for remote access to postgresql server.

Thursday, March 5, 2009

JSON

JSON is an acronym for JavaScript Object Notation. It is a means of transferring serialized JavaScript objects so that a JavaScript application can evaluate them and transform them into JavaScript objects which, the application can utilize to perform its operations. In short, JSON is a data interchange format. It is easy to parse and generate in almost any language.

A sample JSON:-
{"continents": {
"asia":[{"country": "india",
"code": "101"
},
{"country": "japan",
"code": "102"
}],
"europe":[{"country": "france",
"code": "401"
}]
}
}


The most notable features of JSON are:-

1.
It is basically a collection of name-value pairs ("key": "value") separated by a colon.
2.
It is not only easy to read for humans but also easy to parse by the machines.
3. Values can be a string, an integer, an object or an array.
Standard literals like True, False, null are also acceptable.
4. Each object is placed between {...}.
5. Arrays are place between [...] and are comma separated.
6. It can be passed using httpWebRequest.
7. Reserved keywords from JavaScript are not allowed in JSON.
8. JSON can be parsed using the eval() method in JavaScript.
9. It uses Unicode.


Common errors like the "missing } after property list" can be corrected
using a JSON validator like www.jsonlint.com




Tuesday, March 3, 2009

Existing database tables and SQLObject

Define the existing table "Bookmark" as a class in python:-

class Bookmark(SQLObject):

_fromDatabase = True # the table structure will be loaded from the database
BookmarkName = StringCol (dbName="bookmark_name")
# dbName is the name of the column in the database, BookmarkName is the name reference in code.
ProjectId = IntCol(dbName="project_id")

(Make sure the indentation is correct)

Connecting to an existing database using TurboGears framework

Your application would need a DB connection to access the database. A connection is how you tell SQLObject to locate your database. SQLObject is an object relational mapper, a software layer that maps data stored in a relational database to an object model in an object-oriented programming language. The connection string resembles a URI in the following format:


scheme://[user[:password]@]host[:port]/database[?parameters]
For instance:
postgres://user:pwd@localhost:5432/db


SQLObject provides a debug mechanism, which can be turned on easily by appending ?debug=True to the end of your database URI in the dev.cfg file.

postgres://user:pwd@localhost:5432/db?debug=True
This would publish the query generated onto the console.
..........

Define the existing table Bookmark as a class in model.py:-

class Bookmark(SQLObject):

_fromDatabase = True # the table schema be loaded from the database

BookmarkName = StringCol (dbName="bookmark_name")

ProjectId = IntCol(dbName="project_id")

# dbName is the name of the column in the database, BookmarkName is the name reference in code.

..........
Using the following code in controller.py you should be able to retrieve the second record from the Bookmark table

 
b=Bookmark.select()
print ": %s " % b[2].BookmarkName






Wednesday, September 3, 2008

Chrome Finish

Woke up with sleepy eyes, rubbed them to clear my hazy vision. Opened my laptop and saw my news of the day. Google releases new web browser "Chrome". My mid-week holiday was certainly going to be busy. Putting on my "testing goggles" I started looking for the download link. Google made sure my hunt was easy. The link started downloading a 475 KB file. A web browser setup? 475 KB? Looking at it in disbelief, I let it continue. After all, who knows with Google.

The setup file when clicked started another download and installation process. So that was it. A 475 KB application to download the actual setup. The download failed at least a couple of time. It was disappointing. Few times it simply hung and the other times it returned me some weird exception message. The link on the error dialog, lead me to no help. Some divine intervention and all of a sudden it finished installation. Few clicks for importing favorites, history etc from my darling Firefox and I see my new browser.

There I am, greeted with the new interface which made my screen look larger. The Chrome certainly gives you a lot of web space, since it removes a lot of not-so-frequently used buttons and tool bars. It makes you forget that you are using a web browser. It keeps it simple and means business i.e. web browsing. The sole focus of the Chrome is the web application and not the browser itself.

I was expecting it to load a default homepage on the first run, which is kinda customary for other web browsers, on the contrary I see my recently visited sites and bookmarks nicely laid out. The address bar has the auto-complete feature, so my butter-fingers will get some rest. I was falling for it.

Performed a few of my mundane tasks, checking emails, browsing, reading news, blogs, watching videos etc., most of the websites opened visibly fast. I wasn't sure but it did appear to be fast. I read about the technology behind Chrome, it certainly is impressive. It has the new Javascript virtual machine, V8, which is said to be a better solution for rich Web applications. So operations like "drag and drop" which were not very smooth earlier would be a breeze in the Chrome. Each tab is said to work inside a new process, which makes the life of malwares difficult. If a bad Java script was using lot of resources you can simply kill it. The Chrome has an all new task manager. Yes, a task manager(shift+esc) just like the windows to terminate a web application which is using lot of CPU/memory resource. Google has moved up, in this respect by treating each open tab as a different web application. With the Chrome, Web applications will now begin to be treated at par with desktop applications. 'One-tab one-process' also makes me believe, the web browser is a purely multi-threaded application. So, one slow web application should not affect loading the other.

One of the cool features, I found was, I could tear a certain tab away from the rest of the tabs. This is particularly useful for some one like me, who doesn't close his tabs during my day. Only when the number comes to about 30-40 open tabs do I think of closing the ones not being used. Now, I can tear away the tabs I would still need(lesser in number), and close the rest(more in number) one-shot.

If I am not wrong the FF introduced the 'open in new tab', similarly the Chrome has a new right click context menu feature, 'Open link in new incognito window'. So my privacy has been taken care of. Anything I open in this window is not saved on the system. This window runs completed isolated from the system.

I am contemplating a shift from FF to the Chrome, but it will take a while as I cant do without my darling FF's plug-ins and most important, the Chrome doesn't have a progress bar. How could you guys have missed it? My serious concern is over the amount of data Google would share with the advertisers. Google generates a lot of revenue from ads. I wonder, if they now get to know every site I open from the Chrome. Does it mean I would be spam-ed more? It raises my personal fear of, 'Google will control the world!'. Web search, Social networking, Email system, Document editing, Photo Storage, Video storage, Mobile platform and now a web browser? Whats next, an operating system?

Keeping all this aside, I would continue to use the Chrome. I am a technology freak. I will continue to use and admire the innovation, as and when it comes.

Final verdict, the Chrome has the shine but lacks the finish.