Category Archives: Web Programming

AJAX, JavaScript, PHP and all web related programming.

Unit Testing PHP using PHPUnit

I spoke about doing Unit testing in PHP using PHPUnit at the Bangalore Open source meetup today.

Continue reading »

Posted in Events/Conferences, Web Programming | Tagged , , , | Leave a comment

Custom themes for PuTTY

This post has sat in my draft folder for more than 5 years. I was doing some cleaning and found that I didn’t publish this post and since it is still relevant I thought of pushing the publish button.

Being a web developer, most of the time I would be staring at PuTTY. I got sick of the default bright colours of PuTTY and was searching for ways to customize the display of my PuTTY window.

After some research, I found pre-packaged custom themes for PuTTY created by Ilya Grigorik. These themes are available as .reg files. You can directly download and use them or if you want, you can further customize them for your needs.

Below is the screenshot of the different themes that are available.


Wow! now my eyes have something pleasant to stare at, most of the times 😉

Posted in Unix/Server Stuff, Web Programming | Tagged , , | Leave a comment

Generating dynamic files for download from PHP

If you have used my WordPress readme generator you would have noticed that I have a “Save As” button, which when pressed allows you to download the file which was just generated by the PHP code. (In most browsers this opens the save file as dialog box)

Recently one of the readers of my blog asked me how to do this in PHP and I was about to send him the code snippet. But then I thought of writing a blog article so that it will be useful for others as well.

So here we go.

The code is mostly self explanatory. The important part in the above code snippet is the “content Disposition” header.

Also since we are sending headers to the browser, we should not have started the output before this code executes. Otherwise we might get a “header already sent” error.

Posted in Web Programming | Tagged , , | 3 Comments

Making text unselectable in browser

Long time back, I was working in a project which required us to make a particular position of text unselectable by the user on a webpage.

I was looking at various JavaScript solutions and finally found the CSS selectable property. But it was not working across different browsers. It took a considerable effort to make it work across different browsers.

I found this code while browsing through archives and thought of posting it here so that I know where to find it, if I need it and also it would be useful for others who want to do the same thing.

BTW, one quick disclaimer. Even I hate it when people make a particular position of text unselectable in a browser. So use it if it is really needed and also remember it is not fool-proof.

Well, let’s see the code then.

Posted in Web Programming | Tagged , | 3 Comments

Expand any shortened url using PHP

Recently for a project which I was working on, I wanted a way to expand urls shorted by url shorteners.

After a couple of web searches I found an API site called LongURL. This service was really slow and I had to look for alternatives.

I thought of writing my own using curl and then parse the headers. I was searching for the curl functions in PHP Manual and I found a simple but not so famous function called get_headers().

This function is all we need to expand the urls. The following function expand_url() takes a short url and will return the longer version of the url.

Enjoy 🙂

Posted in Web Programming | Tagged , , | 11 Comments

Installing PHP 5.3.x in Ubuntu through apt-get or aptitude

Recently, I wanted to play around with some stuff which is available only in PHP 5.3.x (more about it later in a separate blog post) and so was looking for a way to install it on my Ubuntu server, where this blog is running.

After poking around a bit, I found that Karmic Ubuntu hasn’t upgraded to PHP 5.3.x yet and the only way to do is to compile from PHP source. Even though I am pretty comfortable doing it, I didn’t wanted to do it, because it is very difficult to upgrade at a later point in time.

I was continuing my research and then found that it is in fact possible to install PHP 5.3.x though apt-get or aptitude. I thought of documenting it here, so that it would be useful for others who want to do the same thing.

Adding dotdeb to the source list

First you should add dotdeb repository to your apt-get source list. Add the following two lines to your /etc/apt-get/sources.list file

sudo vim /etc./apt-get/sources.list

Adding dotdeb keys to keyring

Dotdeb packages are GPGsigned. Issue the following commands to add the keys to key-ring

Install PHP5 packages

Then issue the following command to retrieve the updated package list. I am using aptitude here; you can use apt-get as well.

sudo aptitude update

sudo aptitude upgrade

And then you can install PHP5 packages (and modules) using the normal install command.

sudo aptitude install php5 libapache2-mod-php5

Installing php5-dev package

The above method will install all php5-* packages, but php5-dev has some dependency issues with libtool packages. In order to solve that you have to manually install libtool v1.5.26. To do that use the following commands.

Now it’s time to enjoy the new features that are available in PHP5.3 🙂

Posted in Unix/Server Stuff, Web Programming | Tagged , | 17 Comments

Code sample to access YQL from PHP

Just wrote quick some code sample to show how to access YQL (Yahoo Query Language) queries from PHP.

You can use the following code sample to fetch results from YQL from any standard PHP file. You would require the curl extension to be installed. If you are behind a proxy, uncomment the 3 lines and replace it with proper proxy values

If you have the Yahoo social SDK installed and you want to access results from YQL, then you can use the following code sample. Replace the text consumer_key and consumer_secret with correct values.

Update: You can also get code snippets for other languages apart from PHP.

Posted in API's/Mashup, Web Programming | Tagged , , | 2 Comments

Get a legal version of Adobe Flex Builder for free

Adobe has been trying hard to build an ecosystem around Flex, which is a collection of technologies for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform.

In order to woo more developers to use Flex, they are giving away free copies of Adobe Flex Builder. In order to get these free copies you have be

  • A student or a faculty or employed in an educational institution
  • A developer who is unemployed due to layoff.

To get these free copies all you have to do is just fill out a form at this link (student, unemployed)

Additional free resources

Together with free copies they are also offering the following

If you ask me, I would say this is a smart move by Adobe to get more developers into the ecosystem.

If you are not eligible to get a free copy, then you can get the trial version of Adobe Flex Builder which can be used up to 60 days for free or buy it in retail for $249.

Posted in Web Programming | Tagged , , | Leave a comment

Everyday learning’s as a web developer

One of the good (and also bad) things in being a web developer is that you have to constantly keep (un)learning. Every time I learn a new trick (like changing the default editor in Ubuntu or searching Google efficiently) or get struck due to some bug or wired behavior, I used to document it here, so that I can refer to it later and also for that fact that it might be helpful for others who are searching for the same problem in Google.

Recently I found one such wired behavior in WordPress while retrieving the categories of a post. I wrote about it and almost forgot about it till I received a comment from a person called kaigou

Insert OMFG or variant thereof, about twenty times, at two in the morning. I’ve been fighting with WP all day to get it to do what I want, and the WP docs have been useless — maybe it’s just that most folks don’t really get into really doing wacky things like nested loops and whatnot, I suppose. I was about to give up when behold, the power of google dropped your post on my screen and NOW IT WORKS. I feel like a keyboard mash is due, or buying you a virtual drink, or SOMETHING. May have to settle for quietly dancing around the house in glee, given that it is two in the morning when most non-geeky souls are quietly abed. But not me! Must celebrate your awesomeness for helping me finally getting it to work! Thank you!!!

It was really a very nice feeling to know that you can make someone from the other side of the globe dance at 2 in the morning. 🙂

This comment has given me the much needed motivation to document the day-to-day learning’s of being a web developer. So guys, from now on, if I spend more than 5 minutes on fixing something I will document it here. I also strongly urge you guys to do the same thing in your blogs and if you don’t have a blog then you are always welcomed as a guest writer here 😉

Posted in Random/Personal, Web Programming | Tagged , , | 1 Comment

IE 8.1 will support Firefox extensions

Update: Well guys, it’s time to reveal that the following post was my entry to April fool’s day. This post has been a hit and atleast a handful of people believed it. So guys, happy April Fool’s day to everyone 🙂

Yes, you read it correctly. IE 8.1 (code named Eagle Eyes) is going to support Firefox extensions. Smashing Magazine has a screenshot to prove it. The first time I came to know about it, I got goosebumps. (Yes really)

If this is true (and I believe it is), then this is the final nail in Firefox’s coffin. The only reason why I continue to use Firefox is because of it’s extensions.
Firefox has become too bloated due to it’s monolithic architecture and had become a huge memory hog. I checked my task manager as I am writing this post and you get the proof. This is with just 5 tabs open.

The major advantage Firefox had over other browsers is it’s huge list of third-party addons. But it cannot rest on it for long. Unless Firefox solves the issue with memory leaks, and comes up with some cool innovation, they cannot retain their market share. Let’s see how Firefox overcomes this new threat from IE.


In addition to supporting Firefox Addons, IE 8.1 also has other cool features like Multiple Browser Rendering Engine Options, Server-side code decompiler, Website Skins etc.

On a related note, even Google’s chrome is going to support third-party extentions. Matt cutts has a tutorial which explains that steps that you need to follow to create extentions for Chrome.

Posted in Web Programming | Tagged , , , , | 4 Comments