Skip to content

Generating RSS feeds

I wrote my first ever rss feed today. It isn’t too complicated, you just output some specially formatted xml with the right mime-type.

The motivation behind this was to replace the default feed in the “Random signatures” feature of Gmail Labs because it contained some quotes which were a little too risque for emails to professors! I wanted to use the unix fortune program, but my hosting service does not have it. There is a webpage which prints the fortune out as html. I took that url and parsed the html (this was the most irritating part because I wasn’t familiar with php regexes) and print that out as rss xml.

To check it out click on the rss icon at prasun.info or directly go to the rss url

Deque

I discovered deque data structure today:
http://www.cplusplus.com/reference/stl/deque/

Both vectors and deques provide thus a very similar interface and can be used for similar purposes, but internally both work in quite different ways: While vectors are very similar to a plain array that grows by reallocating all of its elements in a unique block when its capacity is exhausted, the elements of a deques can be divided in several chunks of storage, with the class keeping all this information and providing a uniform access to the elements. Therefore, deques are a little more complex internally, but this generally allows them to grow more efficiently than the vectors with their capacity managed automatically, specially in large sequences, because massive reallocations are avoided.

Wordpress upgrade

Just upgraded to Wordpress 2.5.1 - the same version which Amitabh Bachchan uses :)

HTML to OPML

OPML is the format used to export/import RSS feed urls.

There is a firefox extension which exports rss feeds in your bookmarks to an OPML file but that has stopped working in 3.0b5.

Since OPML is a relatively simple XML-based format, I was able to do the conversion by hand (the process is scriptable, but I don’t have a need to script it right now). You can do it as follows:

  1. Export Firefox bookmarks as html.
  2. Filter feeds: grep -i feedurl bookmarks.html
  3. Rearrange each line using regular expressions.
  4. e.g. each line in my file was :
    <dt><a feedurl="feedurl" href="url">text</a>
    In vi, I replaced each line to :
    <outline type="rss" text="text" xmlUrl="feedurl" />

  5. Added the header and footer (see example: http://www.scripting.com/feeds/top100.opml)
  6. Find/replace special characters like apostrophes, ampersands, question marks etc

sync music

What do you do when you have a music device but no obvious music player that syncs your player or even recognizes it as a music device (e.g. if the “device” is a USB stick or an SD card).

Well, you write your own — as long as the device supports the Mobile Storage Class (MSC) mode. I don’t know what you need to do for Media Transfer Protocol (MTP).

I just wrote a little shell scipt which is just a fancy rsync wrapper which does this for my Sandisk Sansa player (and any SD card , USB stick etc).

I use Rhythmbox (or any music player) to generate custom playlists (usually based on Artist, Genre or just Play Count) and export it in m3u file (which is just one filename per line and saves you the parsing hassle).

I then create a temp dir containing links to the actual files and sync this temp dir with the device using rsync (before which the device has to be mounted).

Grab the script here if you want to.


More on MTP and MSC

PS: This of course only syncs files and not metadata like play/skip count etc. But the sansa player doesn’t support that anyway

Why Audible.com sucks.

I recently bought a Garmin GPS which plays Audible audio books. With it came an offer of 3 free audio book downloads (it appears that the offer is for anyone who signs up, not just for new garmin customers).

You would think that it would be as simple as Download, Play & Listen. You’d be wrong.

First of all, to download you need Windows/Mac. No downloader for linux, no option to just , you know, click on a link and save on your computer.
Secondly, the format is proprietary. You need special software from Audible to play the files (again, only Windows/Mac)
You aren’t allowed to simple copy the file on any device. You need to use the software to copy the file to up to three devices. And you are asked for your Audible.com login/password while copying. That probably means you can’t copy the file from your computer to your music player without a internet connection!

Tech tip

To move/delete all songs of low bitrate :
Make a playlist in Rhythmbox (or iTunes, banshee etc - any player which allows “Smart” Playlist).
Select bitrate < x as the selection criterion.

Save this playlist with an m3u extension.

On a shell type:
cat playlist.m3u | while read filename; do mv "$filename" folder/; done

Tech updates

Find files not matching a pattern:
find . ! -name \*.mp3

Moving Wordpress:
Create a database and imported the sql dump from old blog database.
Edit wp-config.php
Troubleshooting:
chmod 644 wp-config.php
chmod 644 wp-content/plugins/widgets/opml-blogroll.php
Up and running!

TigerWiki:
Fix locked page : chmod 777 the page which is locked.

“Move to Trash” on NTFS/Ubuntu:
If “Move to Trash” does not work for files on NTFS partition do the following:
change mount options in fstab. uid=1000 (your uid from /etc/passwd)
remount the partition.
This changes the owner of the files on the ntfs partition.
A file called .Trash- is created in /media/sda4 (root of the partition) and acts as recycle bin

ps2pdf - auto rotate

ps2pdf looks at the text in a page and decides to orient it accordingly! I learnt it the hard way when I kept getting pdfs which had a page with a figure rotated.
The fix is : ps2pdf -dAutoRotatePages=/None file.ps

gdb: pointers as arrays

Simple but useful tip for myself:
to print a pointer a as an array of size len
(gdb) p/x *a@len