Friday, December 17, 2010

Drupal: Showing related content based on taxonomy

Everyone knows that the taxonomy module allows one to categorize your content using both tags and administrator defined terms and is very flexible for classifying content. You can create one free-tagging vocabulary for everything, or separate controlled vocabularies to define the various properties of your content.

By using views in conjunction with taxonomy, one can easily create a block of related content.

For example on www.OyeStyle.com, we have articles categorized by one vocabulary called as "Main" and another vocabulary called as "Subcategory". These contain a fixed set of terms. We also allow a taxonomy with free-flowing tags for that much more flexibility and further categorization.We wanted to show a block of related articles based on the taxonomy on each page and of-course views was the answer. The link here at http://drupal.org/node/65375 details out as to how to go about it for D5 and D6.

However due to the free-tagging entries, we were ending up with a long list of articles diluting the "meaning" of related content in some ways. Here is how you can pick up related content by using specific taxonomies by avoiding free tags:

After following the instructions above in the drupal link, go to your view and edit the "Taxonomy: Term ID" argument. We then need to modify the PHP code specified for the default argument handling. Modify it thus:

$node = node_load(arg(1));
if ($node && $node->type == 'article' && $node->taxonomy) {
foreach($node->taxonomy as $term) {
$vocab = taxonomy_vocabulary_load($term->vid);
  if (empty($vocab->tags))
      $terms[] = $term->tid;
}
return implode('+' , $terms);
} else { return; }

The key difference in the above code is that for each taxonomy term associated with the node, we are getting the vocabulary associated with it . We then check if this vocabulary allows free tagging and ignore it if so (the empty($vocab->tags) check does this). Do not worry about the performance implications here, the vocabulary will most probably be cached across future calls. One can possibly do other modifications to the above code. For example, lets say you only want terms from a specific vocabulary. That can be done by:

$specific_vocab_name = 'Main';

$vocab = taxonomy_vocabulary_load($term->vid);
  if (strtolower($vocab->name) == strtolower($specific_vocab_name))
      $terms[] = $term->tid;


The above code will only pick terms belonging to the 'Main' vocabulary.Basically modify the vocabulary checks appropriately to get the desired results.

I hope this was useful. Check out the working functionality on Oyestyle by browsing through the articles there! :)

Monday, October 11, 2010

CDN with Drupal and Parallel module

Am getting good exposure to Drupal land and am loving it so far. I have to be hands on for my work and that is the best way to gain knowledge and expertise - be hands on, nothing beats it!

The current speed of www.oyestyle.com is pretty good, but I wanted to be armed for the day we hit bigger numbers :), so I was testing out the possibility of using a CDN to serve out the static javascript, css and image stuff on the site.

First, I also looked at some Indian CDN offerings. Obviously if the data is being served from close to India, it will help the target audience. But both Airtel and Tata offerings seem to be out of the reach of people who are just starting out. I also checked out the Marcellus guys, but they seem to specialize only in videos. Am thinking and looking at MaxCDN guys currently.

Anyways, the article is about setting up a CDN quickly. For this, we are planning to use the Parallel module. It is not strictly a CDN module per se, but what it does is that it allows you to specify [sub]domains that you can use for your js/css/image files. The page preprocessor code then replaces all references with those domains. This is all you need to do to set it up!

If you have a pull-based CDN like MaxCDN on the other side, then you do not have to upload any files to it too. If it cannot find the file, the cdn will fetch it from my server and then serve it from then on. It will handle this transparently! Will get back with my experience soon :)

Wednesday, July 7, 2010

Drupal source code and [g]vim/cscope

When you start looking at modules developed for Drupal - you kinda get lost amidst all the references to different system functions - user_external_load, db_query, etc. It becomes really maddening!

Fortunately a cscope-enable gvim binary will ease out the source code browsing angst to a large extent. Amongst all the other things, here is what I have in my .vimrc

if has("cscope")

   function! CScope_Refresh()
cs kill 0
 !find $PWD -name \*.php > files && cscope -b -i files
!find $PWD -name \*.js >> files && cscope -b -i files
!find $PWD -name \*.module >> files && cscope -b -i files
!find $PWD -name \*.info >> files && cscope -b -i files
!find $PWD -name \*.install >> files && cscope -b -i files
!find $PWD -name \*.inc >> files && cscope -b -i files
cs add .
!rm -f files
endfunction
comm! -nargs=0 R call CScope_Refresh()
endif

After you have sourced your .vimrc again, you can navigate into your Drupal install directory, fire up gvim and just hit :R and you will be able to search for symbols, look for references to functions, look for files etc. using the standard cscope commands:

e.g.:

:cs find g user_menu

The above will lead us to the definition of the user_menu function in user.module. 

Hope, this post will relieve some of your source code browsing pangs :)

Sunday, June 13, 2010

Why Drupal..

The first major decision that we at had to take at Yuva was about which infrastructure piece to use for the first version of our product launch. Our's is a web-based product. We want to incorporate elements that engage and inform the user-base in various interesting and socially-viral ways. We also want to provide group based interaction, public-private access control features etc. etc. I hope you get the drift! :)

Coming up with hand-crafted code to do all the above seemed a daunting and an insurmountable task given that we want to be out there ASAP. It was then that we started looking around for open-source alternatives.

Drupal and Joomla came up trumps in that research. The idea was to take something off-the-shelf, understand it better and then customize, extend it for our needs. Then come the difficult part of actually deciding between these two. Googling up can actually be a frustrating exercise. For every positive reference you will find an equally disparaging remark too. For every positive user case study you will find an equally pulling-my-hair-off-in-frustration use case too. Tough job!

In the end we have decided to go with Drupal. They seem to have a large thriving community and a lot of websites seem to be coming up on its platform. Additionally Drupal 7 (when it will be launched) seems to further improve on the capabilities provided and the user-friendliness aspects too. Finding good Drupal talent (to hire) based out of India has been an issue so far. But we are trying to build the expertise in-house, because this is a core-requirement which we think we  cannot out-source at all.

Will post back on our Drupal experiences in the coming months - stay tuned!

Thursday, February 12, 2009

Me, my phone and my calendar!

Recently, I got the entry level HTC smartphone for myself. The 3400i is a VFM phone with all the bells and whistles one would need in an entry level smartphone. Whenever I change a phone, the biggest headache is moving around the contacts and the calendar information. I tend to forget and rely a lot on the calendar to remind me about important events like birthdays, marriage annivs and the likes.

I was looking forward to a dreary timespan trying to update my calendar on the phone for all those important events. Its just today that I read about GoogleSync for mobile phones. Via GoogleSync one can sync their googlemail contacts and calendar events immediately with their smartphone! I was sceptical but it was a total breeze. I just had to enter my gmail address details in ActiveSync (yes mine is a Windows Mobile phone - no bricks please :P) and lo-and-behold my gmail contacts plus all calendar events were uploaded wirelessly onto my mobile! Nice, I say :D

What are you waiting for, go get your mobile synced up!

Friday, January 2, 2009

FC10 woes

So my last posting mentioned the reasons why I upgraded my laptop from FC8 to FC10. But the recent events have left me flabbergasted :(

Last week, the automatic update system informed me of the availability of a new kernel (kernel 2.6.27.9-159.fc10) and I dutifully installed the upgrades. The machine stopped booting up since then! It would directly go to the GRUB prompt and nothing else would occur. 

I thought I will just boot up using a CD, mount my drive and edit grub.conf to start using the machine again. I did so and thankfully the Linux partition started booting up again normally. But in this process my Windows Vista partition got totally messed up (again due to the grub manipulations I would think) and goes into a recovery and rescue mode on every bootup :(. Attempts to mount the partition from within Linux also comes out with an error! 

Now darned if I had taken a backup ever!  To summarize, I have lost my windows partition along with all the data on it and am now in the process of a re-install of WinVista. That this laptop is where I do my work on is what makes matters worse. 

Lesson learnt - do not upgrade to a bleeding edge technology unless it has settled down or you BLEED like me. Guess I should have gone to FC9 first... 

Wednesday, December 3, 2008

FC 10!

So a while ago, I upgraded my laptop from FC8 to FC10. It was a pretty simple process because the upgrade operation identified my existing FC8 partition and smoothly upgraded in roughly an hour and 30 minutes without asking for too much. Simple, nice and easy I say. Anyways, here are some reasons why you should upgrade to FC 10 (or this is what Redhat claims to be the reasons):

#1. Speeding Up the Boot Process
#2. The Excellent Solar Theme
#3. Making Printing Snappy – and Attractive
#4. Better Webcam Support
#5. Improved Virtualization
#6. Live image creation tools
#7. Global community efforts
#8. PackageKit (user-friendly yum!)

Read more details about the above and some more here. And let me close this entry with this quote that I read somewhere today :)

"Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)"

Friday, July 25, 2008

Search Recursion

Something funny happened today. All of us google - ummm to search. Even I was doing it. I was trying to use the "screen" utility on my test machine, so that I could start my test and log out and get back later to it. When I gave the "screen -r" command to reattach, I got the following error:

Cannot open your terminal '/dev/pts/0' - please check.

Some permission issue I guessed, so I thought I will search for the solution by googling. I searched by entering keywords like "screen, terminal, cannot, open" etc. etc. and clicked on the second link that came in (As as aside, which search link do you open from the search results? Should do a poll I guess :)).

I got on to that specific page and instead of getting the answer I get the following blurb:

"This is a common problem. Googling will help here"

Hmmm, scratch-scratch, I just googled didn't I? But I think instead of giving out solutions, people have actually started to say "google out and get it" nowadays. Will there come a day when all results we get be like the one above :P

Btw, a simple chmodding of the pts entry seems to help here for non-root users above..

Thursday, July 17, 2008

Batch Image Resize on Linux

Isn't it the same case always. You go out on a trip somewhere. You become trigger happy and click loads of pictures. You come back and want to share it with friends and need to upload them to either picassa or flickr. Now typically if you use a 6 plus MPixel camera, the pictures generally come out to around 1.7MB in size. Uploading a lot of such pictures is a big pain.

I recently discovered the convert utility on Linux. Using it is pretty simple. Here is a small script that I use to batch resize my pictures before uploading them:

for file in *.JPG;
do echo "Resizing file $file ...";
convert -resize 640x480 $file $file ;
done

Check out some pics (Portland visit for RailsConf) that were uploaded after the conversion above here.

Monday, July 14, 2008

iPhoney!!

Hmmm, if you go to techcrunch, the last 15-20 posts have been about iPhone. The hype, the apps, the wait and the likes. Seems to be some sort of a frenzy out there in the US for the next 3G phone from Apple. I even watched the somewhat funny video at this posting for waiting in line for 5 plus hours without any results.

I was trying to compare this with whats happening back in India. Vodafone did some adverts about launching the iPhone in India and I did contemplate for a second or two about sending them an sms about wanting to be one of the early users. But thats about it, I guess. I think people in America tend to have this ME FIRST mindset a lot. Long lines for the Wii, new star trek movies. Camping out for some new game launch etc. etc. I guess South Indian movie fans do this ;), but generally I do not find such fanatical single mindedness happening for such kind of stuff around in India.

Guess most Indians have more pertinent things to think about..

Wednesday, June 25, 2008

Fancy this Jam?

Hmm, some people say Google has the potential to be the new evil post M$. But you got to admit, there are some things which they do pretty well. Amongst that list, is the Google Code Jam. I participated in it once 3-4 years back. I would say it is kinda favored to those who are used to heavy API based C++, Java programming. More so for string manipulation based programming. For me, who has been mostly doing do-everything-yourself C language coding, it gets a bit (not very though and this is not to discourage C coders at all!) tough timewise. But nonetheless its a pretty interesting activity to participate in. Click here for this years details. Happy Code Jamming!

Wednesday, June 18, 2008

Get and Spread FireFox!!

One way to take a stab at M$'s evil world domination plans. Replace Internet Explorer with the Firefox browser! Infact 17th June is download firefox day and they are aiming to set a Guinness World Record by targetting 5 million downloads in a single day (scratch, scratch - no one knows the existing download record though).

I have already downloaded and added my 1 to the global counter :). Infact downloads from India seem to be around the 35,000 mark. Wake up Indians! download now!

The global count appears close to the 5 million mark already! Check it out here!!

(P.S. This posting was done out of Firefox 3 :))
And here is my certificate!

Thursday, June 12, 2008

Coordinated debugging

I code in C mostly. I err and hence I debug too once in a while :). Have been using plain gdb for user-land program debugging for quite a while and it serves all my needs. Fast, from the command line, all the required bells and whistles (including readline) and I don't need no more.

And I even wonder how people use bulky IDEs like eclipse just to debug their programs! But lately, I wanted to browse the source code automatically while debugging. The alt-tab combinations to switch from gdb back to my source files in vim was getting a bit too tardy for me. And I had actually started considering thinking about an IDE (yuck...). But no more, presenting gdbtui!

Its gdb itself, but with the added convenience of co-ordinated source code browsing from within the terminal window itself! I was definitely happy to discover this gdb add-on today! Here is a screenshot that someone posted on flickr for you guys too. Definitely worth a try!

Monday, June 2, 2008

RailsConf - Day 4

Final day! We had to check out from the hotel in the morning itself. Denis, George are seasoned travellers and they were all ready and packed up at breakfast time! I was having some trouble adjusting to the additional 3 hours of lag introduced by travelling from the east to the western parts and arrived late for the breakfast too because of it. Denis then told me to check out of the room in 5 minutes. I made it in time by unceremoniously stuffing clothes, etc into the bag. My bag is a bit heavy. I always commit the mistake of carrying more clothes that I end up wearing on my visits :(.

Denis/George were going to speak about our RubyES - Ruby Enterprise Stack using PostgreSQL. We reached the convention center and prepared some pamphlets to spread the word about our session which was at 10:45 AM. Since it was the last day, the crowd was somewhat thinner at the venue than before. The session went well with a good round of Q & A at the end. Go here if you want to learn more and would like to play around with the stack. And if you want to know what I did in this stack, you can check out my screencast here too. The screencast was created using Jing. Check it out, my voice shouldn't scare you away :)

It was a half day session and our flight was at 9:55 PM. So we spent the remaining time at the bar in the Marriott that we had been staying in. We watched a bit of Shallow Hal, with Jack Black still being funny everytime I watch it. Denis and I also nursed some beers. I also had a shot of Goldschlager (which actually contains pure gold in it!) towards the end to get me into a sleepy mood for the flight :)

Got on to the flight to end my first RailsConf. It was not too bad!

RailsConf - Day 3

Day 3 was the last day for the exhibitions. So we again had good attendance at our booth. One thing that we noted was that all people tend to use MySQL as their database of choice just because everyone else is using it! Many did not understand the difference between MySQL and PostgreSQL and hence why they should use PostgreSQL in the first place. All of us tried to explain as best as we could but here is a link which explains in greater detail as to why PostgreSQL is a much better choice as compared to MySQL.

The breakfast and the lunch facilities during the conf were excellent and the Portland Convention Center is a huge facility indeed. But since there were so many attending the conference, it was pretty hard to get onto the wireless network there. One thing though that gave me some sort of a complex during the conf was that almost everyone who came to the conf were using the Apple Macs! I felt out of place with my lenovo thinkpad there :). Also many companies like Sun, Thoughtworks held a lucky draw and the winners were awarded free Mac Airbooks towards the close of the third day! Yup, I did enter but was not lucky this time around. Maybe next year. I did get my share of free tshirts though ;)

We ended the day by having dinner at a sports bar where I introduced Denis, George to some cool Ultimate Fighting Championship fights :). Denis refused to believe that it is a sport as he likened it to dog fights.

Saturday was also the occasion of the Rose Starlight Parade and Marathon so there were a lot of people out on the streets. It was good for me to see families sitting along side the road waiting for the marathon and the parade to pass by. I stayed around for a while to cheer up the guys participating in the marathon, but as it got a bit chilly later, I prefer to watch some of the action from the comfort of my hotel room before retiring to bed. Final day coming up tommorrow!

Saturday, May 31, 2008

RailsConf - Day 2

So the brainstorming continued pretty late from day 1 and eventually I slept pretty late with the promise of waking up early in the morning. Today was the first day of our booth right! Also I along with Denis, George had to record screencasts of the respective things that we had worked on. We had a 5 minute limit and my first recording was a disaster. It was a full 12 minutes long :)

The 2nd recording was agonizingly close to completion but I ran out of a precious few seconds before I could complete it, very frustrating. Eventually on the 5th try I was able to record a decent screencast. George is going to upload it and when its done I will share the url so that you all can check it out and see what I have done :)

We had good attendance to our booth. People were a bit confused about what we do exactly with Postgres and the Oracle spin on it. Also some wanted to know what exactly was the key differentiator in our RubyES stack. We had some interesting conversations with a guy from the Heroku booth who was using Postgres. In general there seemed to be a lot of curiosity and intent to use Postgres with rails app, which is definitely a good thing!

In the evening a company called as FiveRuns hosted HAPPY HOUR at a local pub, it was pretty crowded when we reached there, so we went to another place closeby. I kinda like the American food that I am getting to eat. Am also enjoying the different kinds of drinks too ;). Well they say, in America do as the Americans do! :)

We rounded up the day by dropping Marie off to the airport. She left ahead of us to go back to NJ. Had had very less sleep the last few days, so I snucked into bed at 9:45PM and got up at 6:15 am today morning. On to the oncoming day now :)

Thursday, May 29, 2008

RailsConf - Day 1

I am/was kind of getting used to the jetlag back in NJ, but now Portland has added another 3 hours to the mix. Its 6:15 PM local time while I am writing this and am already feeling sleepy here.

In the morning, me and George were quite hungry as our last meals were just the burgers that we have had on the flight from NJ. After the breakfast, we headed towards the Convention Center where RailsConf is being run. We took the Red Train or something to reach it. Was pretty impressed with the infrastructure here in Portland. I mean this is a decent tram which takes you FREE OF COST across major portions of Portland. When does one think this will happen in India?

The convention center was pretty good and we attended some of the sessions/tutorials. The attendance also seems pretty decent this year around. We headed back to our hotel for lunch with Denis and Marie. And after lunch, we have been holed up together in a room working on our rails stuff and what all we plan to do!

The brainstorming is still ongoing as we speak, so I better get back to it, now! (still groggy though...)

Wednesday, May 28, 2008

Conferencing the Rails!

Conference time is here. I was supposed to go to the PostgreSQL conference, but am going to the RailsConf instead. Actually wanted to go to PGcon, cos that would have been my first and it would have been a great chance to meet up with all the leading lights from the community. Also Pavan was going to present HOT there and we had plans to check out Toronto and Niagara falls after the conference too. But couldn't go as I am working on some cool Ruby on Rails stuff and wanted to see how it shapes out during and after RailsConf. Right now am in my New Jersey ready to fly out to Portland by the evening. Its going to be a 6 hour flight! USA IS a huge country. I think India by flight from North to South tips wont be more than 3 hours. Thankfully jetlag has not afflicted me much and now the trip westward towards Portland might add some more effects :) Lets see.

Thursday, May 8, 2008

SUNshine makes MySQL happy

Well, well, well... my last posting mentioned a link on slashdot where there was an announcement about MySQL mentioning intentions of close sourcing some of the stuff for their paying customers. As expected, there was a lot of hue and cry over it. Guess some in the PostgreSQL camp were happy rolling their I-Told-You-So eyes too.
It turns out that SUN and others in their camp have paid heed to all and again this link on slashdot says that they WON'T be close sourcing afterall. Interesting stuff this.. I wonder how many times companies have even been influenced in such an OPEN manner to do something of this sort. But GOOD I say :)

Thursday, April 17, 2008

Don't let the SUN go down on MySQL

There is a posting on /. about Sun deciding to close source some parts of MySQL. Hmmm, after paying 1 Billion Dollars in cold hard cash, its expected that Sun will try out some experiments to try and generate a revenue stream. But guess this will rub existing free users off the wrong way atleast initially as a knee-jerk reaction. Guess it will be good for PostgreSQL though :).

But to be fair, its good to see Marten Mickos (previously CEO of MySQL and now SVP at Sun) try and put out reasons for this latest move. All in all, this bodes well for my favourite DB - PostgreSQL :)

Note: The views expressed above are entirely my own personal views.