Wednesday, July 28, 2010

Git instaweb

I'm not a git user actually, not seriously. But for 'unknown' reason, I decided to use git for this one project. Maybe because it is a drupal project and drupal.org currently on path of migration to git from cvs.

Using mercurial, it's easy to browse your current repo through a web interface. Just type "hg serve" inside your repo would launch a local python web server that you can use to browse the repo with browser. Git also come with gitweb but the last time I look at it, you have to configure your apache to run the Perl cgi script. I want to avoid that and I look around for alternatives. Something in PHP would be good but none seem to be usable enough. So I take a look back at gitweb and through reading the documentation I found out that git now also provide "git instaweb" command that would launch web server to serve the current repo using gitweb interface. This is much like "hg serve" and I'm glad that git now also has it.

"git instaweb" by default would use lighttpd for the httpd daemon but you can supply alternate httpd daemon such as apache. For apache, "git instaweb -l --http "apache2 -f" would start the server and launch your default browser to browse the repo. You can also put this into .git/config:-

[instaweb]
local = true
httpd = apache2 -f
port = 4321
browser = google-chrome

Thursday, July 15, 2010

Selenium RC headless on linux

My laptop is slow enough with only 1.2G RAM and I don't want to make it even slower by running the Selenium server and an instance of Firefox (I used Chrome all the time). Better make use of the idle dev server at the office. So I'm thinking of running the Selenium server at the remote machine and use ssh tunnel to proxy port 4444 on my laptop to port 4444 on remote server. When running the test, the server gave an error message "Failed to start new browser session ...". Already expecting this since X is not running on the remote server.

Googling around, the solution is simple. Our old friend X frame buffer to the rescue. So just apt-get install xvfb and use the following command:-

$ Xvfb :1&
$ export DISPLAY=:1

and then restart the Selenium server. You can see the test running now through the console (of course you can't see the real browser opening up). For some reason, Xvfb doesn't return my prompt so I have to explicitly put it to the background with '&'.

Selenium is usable and I'm very happy

I always thought Selenium is hard to use and doesn't worth my time. So in the past, I used twill to create a script (python) that would go the site, filling in any forms and did all tests that I would normally do by hand. It's a life saver. You don't want to fill in the large HTML form by hand every time you need to test your app. Using twill, I can just press the Enter key and it will run all tests I want. I can even go take some drink and snacks while the tests is running and get back to see whether it success or not.

But there's one downside with twill, you need to crafts all the test script by hand, looking at each form field you need to fill in. So this time I think it's time to start looking back at Selenium. All cool guys out there are using it to test their applications, it shouldn't be that hard. There's 2 parts of Selenium (actually it's more than that but for now I'd only interested in that 2 parts):-
  • Selenium IDE - Firefox addons that allow you to record your interaction with the browser.
  • Selenium RC - Consists of a server (java application) running on (by default) port 4444 and a client that would connect to the server, open up your browser and running up the test case specified. The client available in few languages - Python, Ruby, PHP, .Net etc.
The cool part is the IDE allow you to export the test case into client language so in the end I can still have something like twill. This is the coolest part. The other cool part is the python client is just a single module that I can copied to my PYTHONPATH and it just work. Now I feel like hugging all my kids and wife telling them, see ... now Selenium is working for me ! Too bad they are all sleeping now ;)

The 'not-so-cool' part, it doesn't work with Javascript popup calendar so you have to enter the date by hand.

Monday, July 12, 2010

Plesk delete domain would delete your entire site !

You read that right, when you delete a domain through Plesk control panel it would actually remove your entire site, including your mysql database. No warning given other than just "Are you sure ...?". For something so destructive like that, one definitely expect the message should read something like "This would delete your entire site including your database ...". Good UI design should closely mimic the real world scenario. When you delete your domain, what you would doing without the stupid control panel is open up the zone file and delete few lines there. Nothing you did there would affect your site code or the database. It just a dns record !

My fault here is I'm assuming too much. I assumed that no sane mind out there would setup the domain record so tighten with the application resources. Turn out that I'm dealing with an 'insane' mind ... sigh.

Here's an example how Webfaction control panel translate the real operations into UI metaphor.
  • You create a domain - The equivalent of adding entries into zone file.
  • You create an application - The equivalent of creating a directory to hold your PHP files or any kind of web framework you're using.
  • You define a website that would associate a domain to application at a given path (most of the time / but not limited to) - The equivalent of creating a virtual host entry in your apache config pointing to the document root or some other handlers.
So when you delete a domain, you just deleting a dns record, not your whole application. Plesk want to be clever though, when you create a domain it would create EVERYTHING so you would get a site up instantly. But when you remove a domain, it would also REMOVE EVERYTHING. The rest is just histrory ....

Sunday, July 11, 2010

Drupal: Redirecting user to specific page after login

Task:
After user logged in, redirect them to custom page (dashboard) rather than the default user account page in Drupal (user). For users with admin role, redirect to something like (admin/dashboard).

Modules available:-
So I proceed with implementing some custom code, copying the trick used in user.module which used menu_set_active_item('dashboard') and menu_execute_active_handler() to render a page for a given request. This work perfectly because it does not use redirect such as in login_destination which would stop script execution, causing some hook and code not fired as in the bug with Content Profile module. This however would only work for real path defined in hook_menu.

Friday, July 9, 2010

GPLHost VPS

Everytime I'm thinking of looking for good hosting provider in Malaysia or Singapore, I would just backed up and said it would be a waste of time. Hosting provider in Malaysia or Singapore still can survive to this millennium of 2010 just because of 2 main reasons:-
  1. Law of physics (read: latency)
  2. Customer ignorance.
You don't need to go further when looking for good hosting provider. Their website frontpage would tell it all and to our luck, they all look similar with each other. I'm wondering if there's 'industry standard' for web hosting's website in .my and .sg. Good hosting provider definitely would look different. Rule #1 - If you see something like pretty lady with a headphone ready to take your call, stop. Go away. (I took this somewhere else but forgot already where it is).

But looking at gplhost website, I eventually noticed something different with the content (though their sites look not much different). Firstly, they're using their own control panel which they release as an open source. This is a good sign. Rule #2 - If you see something like Cpanel/Fantastico/DirectAdmin/Plesk etc, also stop. This is just a bunch of guys who know how to run few linux commands and suddenly they have a hosting company ready to take victim, sorry customer.

I don't have to look further. Luckily hostingfu (my trusted sources for web hosting related stuff) have been with them for sometime and has few stories to share.