Tuesday, June 08, 2010

Gnome Thumbnail Cache Cleanup

Rationale
Gnome creates and stores thumbnails when you view a directory containing images or videos. These thumbnails are never deleted, even though you might not ever need them again. Thousands of these cached files could take up hundreds of megabytes of disk space.

Solution
The following script will delete the cached thumbnails older than n days, with n = 30 in this case.

test -d ~/.thumbnails && find ~/.thumbnails -type f -atime +30 -exec rm "{}" +

The same script could be scheduled to run periodically by adding something similar to this in crontab. In the following example, the command would be run once a month on the specified date and time:

17 03 10 * * test -f ~/.thumbnails && find ~/.thumbnails -type f -atime +30 -exec rm "{}" +

Other Considerations
On my box (Core 2 Duo, amd64, 4GB, 80GB, 5400rpm) it took about 0.2 seconds to delete 1500 tiny cached images. This number could vary wildly, but is very unlikely to hog the system resources in any case.

Tuesday, December 01, 2009

Plotting with "gnuplot"

gnuplot is a versatile open source tool for plotting charts. Besides a low memory footprint, it has several features that make it indispensable.

Unfortunately, it has a bad reputation for creating ugly charts. But then, Linux is difficult because things will just never work. A pig was flying outside yesterday. This list can go on forever.

gnuplot does NOT produce ugly outputs. In fact, the output is professional enough for any use. It's the user who mis-configures the program and then whines.

In my recent presentation Plotting with "gnuplot", I demonstrated creation of a clean and simple chart in gnuplot step-by-step. This is what I ended up with:



For a guided instructions and code for the above chart, check out my presentation Plotting with "gnuplot".

Wednesday, August 26, 2009

BarTime bot, Google Wave campout

I've been planning to blog on a regular basis, but time is the biggest constraint. Though still being overloaded as usual with work, now I'm planning to post more often. Here's some interesting stuff going on in my life:

I attended the Google Wave campout at the Googleplex earlier this month. About 250 people got together and coded over the weekend, and came up with several practically usable products and apps. People grouped on the basis of the brainstorming and speed dating catalyzed by the organizers. Coding continuously for 2.5 days in a team with strangers was great experience, even though we weren't strangers anymore by the end of day 3.

My team built a Beer Time bot and gadget for Google Wave. It sits in a wave conversation analyzing the messages being exchanged. When it senses that conversation is getting hostile and "hot", it tells people to chill IRL and proposes a couple of beer bars in the vicinity based on the participants' locations. Participants get to vote on bars and go chill. In a nutshell, it is a bot that makes people socialize - in real life.

We got third prize for this. And yes, there were more than three teams there. :)

The project is published under GPL. Check the presentation and the source code.

Monday, April 06, 2009

HOWTO Trim a string in bourne shell

The objective is to strip the leading and trailing spaces from a string in a comfortably easy way.
I searched several places and couldn't find a reasonably simple way of doing this. Some forums suggest using bash substitution, others recommend the use of complicated commands in `sed` or `awk`

Here's a nifty little trick that does the job without involving any complex commands.

Let's say you have a variable named 'a', as follows:
$ a=" one "
$ echo [$a]
[ one ]

Note the leading and trailing spaces. Now getting rid of them:
$ a=`echo $a`
$ echo [$a]
[one]

Trick is that `echo` automatically ignores the leading and trailing spaces of its arguments. We're executing the command `echo $a`, so the value of $a is fed to echo, which in turn outputs the trimmed value. Simple, wasn't it?

Saturday, December 06, 2008

403 Not Found? 404 Permission Denied?

This is not the standard:


CMU, one of the top universities in the world, offers one of the best Computer Science programs. Wish their servers got some attention too.
Upon hitting an HTTP error page, I couldn't figure out the problem. Looks like I being denied the permission to a resource that does not exist. Is that a 403 Unauthorized? Or a 404 Not found? Even if one of those is true, I wouldn't "try again"; unless it is a 401 which calls for repeated attempt with credentials. Even that wasn't applicable in my case.

After this got beyond my understanding of simple error messages, I pulled up Firebug's Net panel. For some reason Firebug decided to give me a hard time and refused to disclose the HTTP response code. Maybe the semantics confused it.


What next? Console to the rescue!


It was an HTTP 403 Forbidden, still unclear whether it was because the page has been removed. Come on, CMU.

Friday, November 14, 2008

bash wouldn't log it

Following technique is simple but handy, to execute commands in bash without having them logged:
  1. Hit spacebar (at least once)
  2. Type a command
  3. Hit enter
  4. Check history's tail :P
$ eject
$ beep
$ echo Something
Something
$ date
Fri Nov 14 13:52:55 PST 2008
$ history | tail -n 5
501 eject
502 beep
503 echo Something
504 history | tail -n 5
Notice how `date` magically disappeared from the history, because of the space(s) before the command.

This trick worked on Ubuntu Intrepid, Gusty and Fedora 9, which had bash 3.2.39. It didn't work with rhel5's older bash, so this is probably a bug introduced in a newer version; or a feature, if you want to call it that :)

Update: This "feature" is still present in bash version 4.0.33(1) on Ubuntu 9.10.

Friday, May 30, 2008

Installing Bugzilla: The easy way

Operating system: CentOS 5.1
Web Server: Apache
Bugzilla v3.0.4 from http://www.bugzilla.org/download/

Note:
- Works on Fedora 8 too.
- Watch for URLs and filenames used below! They might change depending on the versions.


Assuming that you're in a superuser shell. If you have sudo access, you might get a superuser shell by executing:
$ sudo su
Download the latest tarball from bugzilla's website using wget or curl:
[/root]# wget http://ftp.mozilla.org/pub/mozilla.org/webtools/bugzilla-3.0.4.tar.gz
or
[/root]# curl http://ftp.mozilla.org/pub/mozilla.org/webtools/bugzilla-3.0.4.tar.gz > bugzilla-3.0.4.tar.gz

Extract the contents of the tarball:
[/root]# tar -zxvf bugzilla-3.0.4.tar.gz
A directory is created with the name bugzilla-3.0.4.

Move the bugzilla directory to the webroot directory of apache server. Here assumption is that you're using the default webroot directory. In case you have a different webroot path, use that.
[/root]# mv bugzilla-3.0.4 /var/www/html/bugzilla
[/root]# cd /var/www/html/bugzilla
Now execute this script, included with bugzilla, to get a list of missing perl modules.
[/var/www/html/bugzilla]# ./checksetup.pl

Fedora: Skip the following step and proceed to installation of the modules.

CentOS 5.1:

Adding yum repository to get the perl modules for
Note: procedure might vary for different versions of CentOS.

Create new file Dag.repo in yum's repository directory, /etc/yum.repos.d/ in CentOS, to get access to all the perl extensions through yum.
# vi /etc/yum.repos.d/Dag.repo
Copy paste the following text to Dag.repo file:
############# Dag.repo #############
[Dag]
name=Dag-$releasever
baseurl=http://apt.sw.be/redhat/el5/en/$basearch/dag/
enablegroups=0
gpgcheck=1
gpgkey=http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
exclude=freetype,htop,iptraf,rsync,syslinux

enabled=0
############# End Of File #############

Install the required perl modules:

CentOS:
# yum --enablerepo=Dag install perl-TimeDate perl-Template-Toolkit perl-Email-Send perl-Email-MIME-Modifier
Fedora:
# yum perl-TimeDate perl-Template-Toolkit perl-Email-Send perl-Email-MIME-Modifier

Install the optional perl modules, for extended features:
CentOS:
# yum --enablerepo=Dag install perl-GD perl-Template-GD perl-Chart perl-GD-Graph perl-GD-Text-Util perl-XML-Twig perl-MIME-tools perl-PatchReader ImageMagick ImageMagick-perl perl-LDAP perl-SOAP-Lite perl-HTML-Scrubber perl-Email-MIME-Attachment-Stripper perl-Email-Reply
Fedora:
# yum - perl-GD perl-Template-GD perl-Chart perl-XML-Twig perl-MIME-tools perl-PatchReader ImageMagick ImageMagick-perl perl-LDAP perl-SOAP-Lite perl-HTML-Scrubber perl-Email-MIME-Attachment-Stripper perl-Email-Reply

For postgresql database backend support,

# yum --enablerepo=Dag install perl-DBD-Pg
Run the following script, found in bugzilla installation directory, to verify the modules and install bugzilla:
# ./checksetup.pl
If any module is missing, install it using
yum --enablerepo=Dag install
In the file ./localconfig, update the values according to your needs and rerun checksetup.pl

When everything is in place, the checksetup.pl script should prompt for an administrator email address, name, and password. Enter it.

Setting appropriate permissions:
[/var/www/html/bugzilla]# cd ..
[/var/www/html]# chmod 755 -R bugzilla/
[/var/www/html]# chmod 777 -R bugzilla/data/

Configuring apache server to allow perl script execution in bugzilla directory:
[/var/www/html]# cd /etc/httpd/conf.d [/etc/httpd/conf.d]# vi bugzilla.conf
############# bugzilla.conf #############
AddHandler cgi-script cgi pl Options +Indexes +ExecCGI DirectoryIndex index.cgi AllowOverride Limit
############# End of File #############

Restart apache server to include the new configuration file:
# /etc/init.d/httpd restart

Once completed, your bugzilla installation is ready to use. Use the browser window to set the preferences and to add users. Happy bug tracking! =P