Categories
Technology World Wide Web

Optimizing website bandwidth consumption

Since the time I have hosted this blog on WordPress, I am looking for patterns and tweaks to optimize my bandwidth consumption. Most hosting providers charge you for your bandwidth, so it is always a good idea to see where you can cut down on bandwidth consumption.

When I say optimize I don’t mean reducing size unnecessarily. A good theme with good content in it is definitely going to add to the user experience of visitors to your site and that shouldn’t come in the way of bandwidth optimization. A lot of these points are closely related to the SEO of your site.

So here are some things you can do to optimize the bandwidth.

Categories
Technology

Getting Rosegarden to work in Ubuntu (Gnome)

I am one of those many people out there who had trouble in getting Rosegarden to “sing” in Ubuntu under Gnome Window Manager. Finally after trying a lot of permutations and combinations, I got Rosegarden to work. I made this post to share what I did so that others don't have to go through the same trouble I did!

So let's proceed.

Required software

Rosegarden requires some other applications to be installed in your system. So before you fire up Rosegarden ensure that you have the following:

  1. qjackctl
  2. qsynth
  3. rosegarden

If you don't have any of these you could execute this:

$ sudo apt-get install qjackctl qsynth rosegarden fluid-soundfont-gm

Ok, now we have everything we need. Let's proceed to the configuration steps:

Start the Jack server

(Somehow not using sudo gave me problems)

$ sudo qjackctl &

Jack Audio Connection Kit setup

Click on Setup
Here are the settings I used:



Start the Jack server



Start the synthesizer

$ sudo qsynth &

QSynth setup

MIDI Setup



Audio Setup



Soundfonts Setup


Start rosegarden

Ok, it's time to fire up Rosegarden.

$ sudo rosegarden &

Configuring Rosegarden

Go to Settings – Configure Rosegarden.




Ensure that the connections are right in Jack Audio Connection Kit (Connect):




Play one of the sample files and you should hear music!



Troubleshooting

In case your Jack server is not running, you might want to execute this command and then start the Jack server:

$ sudo /sbin/alsa force-reload

Update

One of the readers of this post, Jason Friedman, sent me this information via mail:

I read the information you posted about rosegarden at http://gauthampai.livejournal.com/62383.html and it was _very_ helpful. Thank you for posting it.

I am running Linux love 2.6.31-20-generic #57-Ubuntu SMP and I had to do two additional things to hear the audio:




Categories
Technology

Adventure with Ubuntu, Wubi, yum, libc and the like

Note: This is not for the casual reader. If you are facing any issues with any of the keywords mentioned above, you might want to continue…

So here I was trying to install some packages from a YUM repository on my Ubuntu 8.0.4 system. Why YUM when you have apt-get? Well, let's just say, the situation demanded it.

The installation seemed to be going fine. What I did not realize is that, the installation had innocently relinked my libc files to a new location (actually to an older version of libc). The yum installation failed. Without checking the error, I executed sudo yum install again.

And I got this:

sudo: /lib/tls/libc.so.6: version `GLIBC_2.4' not found (required by sudo)
sudo: /lib/tls/libc.so.6: version `GLIBC_2.4' not found (required by /lib/libpam.so.0)

Next I executed ls. Same error! And soon I realized, I was not able to execute most of the commands. The only things running were, things that were already open. I had closed my terminal by then, and was not able to bring it back neither was I able to login in an alternative terminal.

It is extremely difficult to figure out what has gone wrong without a terminal. I tried out various things, but I soon realized that since I don't have sudo access anymore, I won't be able to fix anything in the /lib directory, so no point trying.

The only solution was to reboot in recovery mode and then see if I could relink the libc files. So I popped in the Ubuntu live CD.

Now here is an added twist to the tale. I run Ubuntu on Wubi. So how do I mount my NTFS 'file' which is actually a Linux partition?

With some pointers from my colleague, I realized that it is possible to mount a file as if it were a filesystem. I executed this:

mount /dev/windows/filesystem/containing/wubi/installation /media/disk
mount /media/disk/path/to/wubi/disks/root.disk /media/root -o loop

Guess what! The Wubi file got mounted and I was able to access the files.

After some inspection I realized that the problem was that, while Ubuntu has all the libc files in /lib/tls/i686/cmov, the message indicated that these files should be in /lib/tls.

I did a 'ls' in the /lib/tls directory and found that there are some files of an older version of glibc at this location but the live cd version didn't have any files there. So it was apparent this is what is causing the problem.

I unlinked all the files, and relinked them to the new location and rebooted.

This time although it was able to boot Linux, it did not bring up the UI. I booted once again in recovery mode and ran xfix and continued with the boot.

Things seem to be fine now.

Update: Not everything was fine. Some applications, like Totem threw a SEGFAULT. So I did this:

sudo apt-get install --reinstall libc6

Things seem to be fine now.

Categories
Technology

PHP Functional Programming – A code snippet

Given a string of comma-separated values, how do you convert each of them into a link of the form:
<a href=”http://–item–.google.com/”>–item–
and return a comma-separated list of these strings?

Snippet 1:

<?php
//Make these links to google.com

$string = "news,reader,mail";

$array_of_string = split(",",$string);

$final = array();

foreach($array_of_string as $item){
	$final[] = "<a href='http://".$item.".google.com/'>$item</a>";
}

echo implode(", ",$final);
?>

Snippet 2 (uses functional constructs):

<?php

//Make these links to google.com

$string = "news,reader,mail";

$array_of_string = split(",",$string);

echo implode(", ",
		array_map(
			create_function('$item',
	'return "<a href='http://".$item.".google.com/'>$item";'
					),$array_of_string
			)
		);

?>
Categories
Technology

Groovy – a cool JVM based scripting language

Ever thought you are so addicted to Java that although the world is talking about moving to functional languages, you just cannot see yourself leaving the JVM?

Well, as Jerry put it, Groovy could be your solution. You can still use the JVM, but instead of Java, use Groovy as your programming language.

Are there any compelling reasons to move to Groovy or even away from Java to any of the scripting languages on the JVM?

Well, I wouldn't consider myself to be an expert in Java, or any programming language, but from the little experience that I have, I should say, there are some reasons I can think of.

Some time back, we had this requirement. We were doing some project on Eclipse and we had to make changes to a basic Eclipse object because an assumption made by the Eclipse architecture was not true for us. Were we trying to break the architecture of Eclipse? May be. Why were we trying to do it? Well, technological coolness!

Anyway, the point is, this is not possible without actually downloading the source and then making the modification and asking users to replace the original JAR containing that object with ours. Or we need to ask the Eclipse community to accept our change and it might not be a compelling reason for the community. Is there a simpler solution?

How would it be if it was possible to modify this object during runtime and not require anyone to replace the JARs?

Well, although I have not tried it, I am sure it is quite easy to do this with a functional language. I have done some similar changes to Dojo using the 'prototype' property.

There are simpler reasons than that. Java sometimes can get really painful. Remember how painful it is to simply replace backslashes in Java? Remember how painful it is to obtain a substring from the 2nd character at the beginning to the last but one character at the end? Remember how painful it is to write a string of HTML to the response from a servlet? Can setters/getters be simpler? Can XML document creation be simpler?

With the world talking about byte-code modification, metaprogramming and scripting languages on the JVM, Java is becoming more of a platform language than a core programming language. It is more like what C/C++ was about 10 years back and what assembly was before that.

So back to my question on why Groovy.
The Groovy guys have answered it elegantly. Here are the reasons that I found to be the most compelling:
1. It has functional aspects.
2. The syntax is neat and consistent.
3. It is Java based. It is easy to move back to Java if I ever need to. Groovy is completely interoperable with Java and reuses a lot of the Java semantics. If you really need to get this, you should see this tutorial.

So go ahead and give it a try! Who knows, you may soon start to wonder why you were doing Java programming all these days!

Categories
Technology

Digitized information and the affect on history

First a bit of background on this post.

It is new year's time and I was busy preparing my resolutions for the next year. Now, I like a systematic method of capturing the information about how I fared and I keep trying out new organizing tools to do so. I have switched from simple notes (as text documents) to sophisticated and personal XML formats to do so.

I decided to use FreeMind as my organizer for this year. In order to ensure that I don't lose time on experimentation with this capturing methodology, I tried it out in the last week of December.

A week's experimentation and I was convinced. It was working out well. In the back of my mind, I was also thinking of the need to take some kind of backup of this data, lest I lose ALL my information because of some stupid mistake.

The stupid mistake was bound to happen sooner than expected. Some wrong keystroke and the file size was reduced to 0. In other words the data in the file was wiped out. I tried using some data recovery software to scan my filesystem and try recovering some backup of the file but it did not work and my week's data was lost!

It was too hard to believe that my data was there just a moment ago and now I don't have it anymore. This made me think how vulnerable our data is. As a co-incidence, the same day, I listened to some podcast where the narrator was explaining the vulnerability of digital data.

Imagine that the entire life form is wiped out suddenly because of some form of 'doomsday' and life regenerates and these new guys don't have a concept of 'digital information'. Imagine that these guys are now doing research similar to the present day 'archeology'. What would they come up with?

“Just a few hundred years back it is believed that there were some intelligent life forms on the earth. We have recovered some evidence that these people were very intelligent. Different people had different roles. We have recovered some highly symmetrically shaped objects. It is believed that a lot of people (yeah, they are referring to software engineers) spent their entire life with these objects. From carbon dating the life of these objects shows that it is very recent, so these people are believed to be doing some very intelligent work although this has not been proven. Also not much inscribed or written data is available from this era. So we believe that they had a sophisticated method of communication.”

Digital data is so different. We can have multiple copies of it. But then it is all upto our interpretation. The pits on a CD represent how my food looked when I had been on my US trip, but only my computer knows how to interpret this information. Updates mean that new data just overwrites previous data. This is quite different from a traditional paper/pen method of capturing information. I don't, for example, have a way of looking at how my idea evolved from the very beginning to the present. The death of a person can also wipe out so much of information about the person residing in various data stores like mail-boxes, bookmarking sites etc, which give a hint about the personality of the person.

The bottom line is that digital data is vulnerable to loss. So whenever you are churning out data remember this fact. If something is precious, move that out of the digital world and into the real world. Data in digital form no matter how many backups you take is always vulnerable to loss.

Just my 2 cents.

Categories
Technology

Multi core uhh… homo sapiens

A long time back in the dense forests of WonderLand, 'people' decided to create a multi core 'processor'. For those who don't know what that is, a multi-core processor contains more than one processor packaged together as a single unit. Computation can then be shared between these processors and the result assimilated.

Now think of these 'people' to be the ones who designed the human brain and the 'processors' to be human beings. Does that remind you of H2G2 or the Matrix? May be.

Ok, now what would multi-core mean in this case? Computation shared between people? Well, how about you calling someone to ask him, which movie you went to last Sunday because you forgot that name? May be.

Ok let's exaggerate this a little more. I am not a technical astrologer, but soon a time will come when your information will be stored across multiple things (both living and non-living) and you just make a mental picture of who has what, or what has what. How many of us now rely on our mental abilities for simple things like addition of a list of numbers? How about your dad's mobile number? Or how about the site where you downloaded that music track? How about your best friend's birthday? Or calling up your friend to ask him which company your other friend is working in. Or the day you bought your bike? The list continues…

Hey! Did I really blog this. Forget what I said, I was asleep.

Categories
Technology

Java and pattern matching

I had a very simple requirement. I had to escape certain characters in a string using a backslash.

Backslash is a very tricky character. Escaping involves preceding the character to be escaped with a backslash. Now, suppose you have a string which contains a backslash, and if you need to escape it, you need to enter 2 backslashes.

The complexity just begins. Backslashes have special meaning in regular expressions. Strings in Java also use backslash with a special meaning.

Combine all this and you reach hell.

I wanted to replace all occurrences of ” and with ” and respectively. Guess how I use Java for this?

	returnString = returnString.replaceAll("\", "\\");

	returnString = returnString.replaceAll(""","\"");

Yeah, that's how you do it!

Categories
Technology

Want a Linux flavor for human beings?

My first experience with any Linux flavor has been usually bad. But this one wasn't.

I had heard about Ubuntu a long time back but somehow could not use it. The requirement of the Internet for installation was too much to ask.

However, I was interested in trying out a new flavor of Linux and so asked for a CD. I like KDE more than Gnome and so I asked for Kubuntu. The coolest feature that I saw was that there was only one CD, which acted like both a Live CD and an installation CD. Boot the OS and if you like it, click on an icon and it installs as if the OS were an application.

There were no hassles. The live CD booted without any problems. I was even able to access the net. was also able to access the net using a USB modem using the Live CD (imagine doing that without even touching your hard drive!). Both of us were excited.

The installation however gave me some problems. (My success rate of installing Linux in one try, thus, still remains at zero! 🙁 ) I had forgotten that I had mounted a Linux ext3 drive and I was trying to format it during the installation. The install process crashed and asked me to refer to some logs for more info (which I did not). Failing during installing Linux is not a big deal! So I tried again.

This time I tried a slightly different option and I was given a clue that I could be trying to format a partition that is mounted.

That was it. I did not face any problems after that.

If you are like others and wants to use open source software, but are shuddered by the idea of a 'Linux installation' or 'package dependencies', try Ubuntu.

There are more packages than you can imagine. There is something (actually a lot) for everyone. You will find applications that you use in your day to day use or atleast find equivalents.

Overall, I am more than satisfied with Kubuntu. Thanks to all the developers and the people behind this wonderful revolution.

Wanna try it out? You can ask for free CD's by asking for it here.

technorati tags:, , , ,

Categories
Technology

Now how do you do this in functional programming

Consider the following piece of code:

...
int flag=0;
for(int i=0;i<10;i++){
   if(val==arr[i]){
      flag=1;
      break;
   }
}
if(flag==1){
   System.out.println("Found.");
}
else{
   System.out.println("Not found.");
}
...

In functional programming, we cannot assign values to variables; variables can only be initialized. So I can't use a 'flag', the reason being that if I initialize the 'flag' outside the for, I can't change its value inside the for and if I initialize the 'flag' inside the for, I can't use it outside because of scoping.

For people new to functional programming, here's an excerpt from Wikipedia:

Functional programming languages have the following features (or should I call it restrictions?):

...Functional programming can be contrasted with imperative programming. Functional programming appears to be missing several constructs often (though incorrectly) considered essential to an imperative language such as C or Pascal. For example, in strict functional programming, there is no explicit memory allocation and no explicit variable assignment. However, these operations occur automatically when a function is invoked: memory allocation occurs to create space for the parameters and the return value, and assignment occurs to copy the parameters into this newly allocated space and to copy the return value back into the calling function. Both operations can only occur on function entry and exit, so side effects of function evaluation are eliminated.

I had such a requirement in my program. I was using XSLT to program something and I came across this requirement. (XSLT is also a functional programming language). I then used some XPath constructs to solve it but wondered if there is a standard way to solve it in functional programming languages.

I am new to functional programming (although I have been doing XSLT scripting for the last 1 year) and I am still looking for a standard solution to this pattern.