Debian – The best Linux distro

Posted by – August 11, 2011

When one of my friend introduced me to Ubuntu Linux I was impressed by its user friendliness. Till that day I had used Red Hat Linux, Fedora and Knoppix. They were not cut out for an average PC user. In my opinion a geek using Linux doesn’t make Linux popular. Its an average PC user who will make it popular. The guy who introduced me to Linux was not a software guy in fact he is a doctor, oncologist to be precise. Ubuntu replaced Red Hat as my preferred Linux distro. Then came Compiz and shiny effects on Ubuntu made me a die hard fan. Till then I didn’t know Ubuntu was based on Debian. Then for more than 2 years, I didnt boot into Windows, when I needed Windows I ran it in a VM environment in Ubuntu. But Ubuntu was for an average user and this year I decided to switch to Debian. It turns out that I made a correct decision.  According to TuxRadar, Debian is the the best Linux distro of 2011! If that wasn’t all, Debian was favoured by Linux.com as their choice of production server.

Use WordPress Update Services to automatically create static XML feeds

Posted by – August 2, 2011

WordPress blogs server Atom and RSS feeds by default. One can outsource this job to a 3rd party services like feedburner. The existing built-in system in WP serves XML feeds on-the-fly. What that means is a if a feed reader/consumer requests your feed then WP is actually querying MySQL, doing all the back-end server side job and serves a hot, out of the oven, feed every time even if the posts are days or months old. This should not bother a very low traffic blog. But then you can set up WP to create physical static feed files using a plugin. This works for most of the scenarios. But I had a requirement that wanted a remote server to fetch and display those feeds. So even if I had set up a plugin to create static XMLfeeds to avoid server hits, the remote server would still need to query my server introducing network latency. There is a way out. WP has a built in update service that tells remote servers as soon as there is a change in blog. This service is known as “WP update service“. This is a sort of RPC service. You can provide WP a remote URL that should be notified as soon as a change in blog occurs. Now its up to that remote service to take an action on it. On my remote server I set up an action which as soon as receives this update message contacts my blog, fetches a feed and caches it locally. Now the remote server doesn’t need to look at my blog until and unless there is a change, of which it will be notified. One can take this a step further. In update services set up the url to a script on same blog that will connect to your blog and create XML feeds along side your blog files in feedsfolder. Use this code in your in wp-content/themes/{your theme}/functions.php

remove_action( 'wp_head', 'feed_links_extra', 3 ); // Removes the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Removes links to the general feeds: Post and Comment Feed

This will stop printing the default URLs for feed in HTML source and in wp-content/themes/{your theme}/header.php add the URLs for actual feed files that now your script is creating. No need to install a plugin. The only drawback I see here is when you update your skin you loose this particular customisation. Other than that its a pretty good way to create static XML feed files and save your server some hassles.

How to cross post status update from Google+ to Facebook?

Posted by – July 29, 2011

Though I signed up on most of the popular social platforms I am addicted to Facebook more than anything. But most of my Google Fan Boi friends are now newly launched FB clone Google+ fans. So they end up posting “things” on G+. Well, I have found a solution to cross post the thing, NOT THE COMMENTS, from Google+ to FB. There are some limitations on what all you can share. Here is how to do it.

  • Log on to Facebook and then go to http://www.facebook.com/mobile/
  • Locate the section “Upload via Email”, in this section you will see, what FB calls, a personal email address. Note that this is not your @facebook.com email address.
  • Note down the address, copy paste it somewhere or keep the page opened.
  • Sign into Google+
  • Go to “Circles”.
  • Create a circle and name it.
  • In this circle add, “Add a new person” and use your personal email address which facebook has given you.
  • Name the this contact.
  • Save the circle.
  • Now go to “Stream” page
  • Try to share some “thing”.
  • Before you hit “Share” button, click on Add circles or people to share with and choose the Circle that has your personal Facebook email.
  • Share the “thing”
  • Check your Facebook newsfeed. Voila!!!

I request all my G+ friends to please share things with Facebook till the time I have all my friends on G+. Moreover I find G+ very strange, people I dont know have added me into their circles. And I tried to follow some celebrities but they simple spam my “Stream”. Even if I comment my comment is lost in 200+ other comments.

find & replace in multiple files using egrep & sed

Posted by – July 1, 2011

Programmers are lazy creatures. Any given programmer would love get things done with lesser keystrokes. For instance, find and replace all in multiple files. I was setting up a project on my localhost that some other guy had done. That guy wasn’t a real programmer otherwise what I did would have not been required at first place. The great soul hard-coded all the hyperlinks. What now? I thought of firing an editor and doing a find and replace all by creating a project. Simple. No. I can use grep/egrep to find things then obviously I can chain it to some other command and replace that text. Yes. I am lazy, so instead of experimenting I did some googling. Here is how to do this. Find all files, recursively of course, in current working directory that contain “teh” and replace them with “the”.

egrep -lRZ "teh" ./ | xargs -0 -l sed -i -e 's/teh/the/g'

egrep/grep takes further arguments like type of files to look for, example egrep “teh” *.txt ./ will search for all text files in current working direcotry that contain “teh”. Cool!

So, you can safely say, I can haz teh Linux power!

M4 – My top secret learning project :-)

Posted by – June 5, 2011

Yahoo! is now going through a very tough time and is being ignored for mostly. There is hardly any attention being paid to Yahoo! products. I recently tried to play with Yahoo! Application Platform and YQL. One can develop web based and standalone applications using YAP SDK and YQL. These apps are more or less similar to Facebook Apps in architecture. I used YQL and quickly created a small site that fetches Sensex data and displays it. Please visit http://www.indianbizdirectory.com/.

The domain IndianBizDirectory.com was lying idle for more than 4-5 years. I ran a small example fetch weather data for Beverly using YQL console. The example is so simple and self explaining. I was encouraged and decided to use YQL in some real life stuff. I used CodeIgniter to set up a project. Codeigniter is my framework of choice for rapidly developing prototypes. I searched for some feeds and web pages for data and as usual Yahoo! and Google were there to help me. Apart from this I hooked up BSEIndia.com, NDTV.com, Bing.com and MoneyControl.com for data. Initially I decided to run real time calls to these data sources. I setup a very basic logger with CI that mailed me every time a call to any data source or feed failed. I asked my friends to start hitting my site. They hammered it for two weeks. It was slow. And occasionally the feed from BSEIndia.com was failing. I studied logs an realised that the speed was slow due to multiple calls, there were at least 4 to 5 calls to different data sources, were making the page slow. I decided to cache the data. This increased the speed. So

  • on every page load, CI checks if cache is available and loads it, if not then it updates cache for that particular data source/feed.
  • there is a background process that caches data for Sensex during trading hours. The cache is refreshed every 15 minutes.
  • there are chances that a feed may fail during the background process, in that case the process leaves the cache in its original state. The cache is updated by CI.

I found there that BSE feed failure log entries were reduced though the data was not real time. After fetching data I used Xpath to transform data into HTML. Result, I could develop a standalone self sustaining website that displays useful Sensex, Forex and Commodity data. One can see Sensex top looser and gainers, clicking on a scrip name shows further detail about that scrip. On top of it, I added Bing search to fetch and display news related to that particular scrip. All in all, it was a great experiment and learning.

To monetize this effort, I added Google Ads on all pages. I wanted to add more ads but don’t have experience with other platforms.

After this, I am planning to dirty my hands with Python, PyGTK specifically to solve a problem I usually face. :-)