Friday, November 24, 2006

Associating mp3 files with xmms in gnome

When I first tried to double click an mp3 file in nautilus (Gnome's file browser), it tried to play the file in Helix. Helix (at least the version on my computer) doesn't play mp3s. I had previously installed mp3 support for xmms (you can get it from 3rd party repositories supported by atrpms), so naturally I wanted to use it for playing mp3s.

The easy way to associate the mp3 files that mostly works is to find an mp3 file, right click it, then click on properties. You can change the default 'action' on the 'Open With' tab. Just select /usr/bin/xmms for the program.

The problem is with trying to queue up multiple mp3 files. If you highlight a group of files and try to play them, only the last file will get played. Xmms is called for each individual file, which clears the playlist.

I created this small script in /usr/bin/xmms-play. It queues up all the files and plays them at once.

#!/bin/bash

# This script works by first making a playlist out of the scripts parameters,
# then .2 seconds later, it plays the playlist.

# Tell xmms to play our playlist in .2 seconds, unless xmms is already queued
# to play.
if [ ! -e ~/.xmms_play ]; then
nohup bash -c 'sleep .2; eval "xmms -p `cat ~/.xmms_play`"; rm -f ~/.xmms_play' >/dev/null &
fi

# This function returns the input parameter escaped. It does this by surrounding# the input by single quotes.
#
# The only character that can break out of single quotes is a single quote
# itself, which means the single quotes need to be escaped. It does this by
# replacing any single quote that appears within the input by '\''. Example:
#
# start ' end
# becomes:
# 'start '\'' end'
escape()
{
local replace="'\\''"
echo -n "'${1/\'/$replace}' "
}

# Take all of our parameters and add them to the play list
for file in "$@"; do
escape "$file" >> ~/.xmms_play
done

Monday, November 13, 2006

Avoiding kernel panic from CD drive

I have a PATA dvd drive hooked up to a PATA to SATA adapter. Why? Because I'm running out of PATA connectors, and I'd prefer not buying an add-on ATA card.

Anyway, this dvd drive doesn't work in Linux. I've left it in the computer hoping that eventually a kernel update will fix that. Unfortunately, after I upgraded to 2.6.18-1.2200 (in FC5), I started getting kernel panics.

The exact error message was:
ata1.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x2 frozen
ata1.00: (BDMA stat 0x21)
ata1.00: tag 0 cmd 0xa0 Emask 0x4 stat 0x40 err 0x0 (timeout)
ata1: port failed to respond (30 secs)
CPU 0: Machine Check Exception 000000000000004
Bank 4: b200000000070f0f
Kernel panic - not syncing: CPU context corrupt


After googling around a little, I found a solution. I had to add the kernel parameter "all-generic-ide". This disables the SATA driver for my motherboard, and the generic driver is used instead. Now my computer boots up, and the DVD drive is even detected, but it still doesn't work. Oddly though, the drive shows up as /dev/hde instead of something like /dev/sda.

In case you're unfamiliar with changing kernel parameters, you can usually get a command prompt from grub when your computer is first booting up. On that screen that lets you pick which kernel or OS to use, try hitting 'e'. Just add " all-generic-ide" (no quotes) to the end of the kernel line. Hit 'b' when you have it ready. When you have the fix ready, to make it permanent, add it to /boot/grub/grub.conf.

Saturday, August 19, 2006

Recovering from bad /etc/fstab

A while ago, when I rebooted my computer I got this prompt:

Give root password for maintenance (or type Control-D) to continue):

After typing in my password, I got a root prompt:
(Repair filesystem) 1#

I was able to find the problem. Somehow I had a small typo in my /etc/fstab file. I must have made it long ago, but never rebooted to have it checked. Unfortunately the partition that it was on was read-only! After a bit of panicking and searching, I found the solution.

First you need to find out which device holds your root parition. Run mount to do this. Next you have to remount the root partition with write access. Here's what the command was for me:
mount -o remount,rw /dev/hda1 /

Monday, June 12, 2006

Easy way to setup 3rd party repos in Fedora

Fedora Core uses yum as its package manager, and yum is based on rpms. Redhat provides a number of updates and extra packages through yum, but even more can be easily accessed through 3rd party yum repositories. Here's how to setup all of these:

1. First enable the atrpms repository. To do that run:
rpm -i http://dl.atrpms.net/all/atrpms-package-config-108-1.rhfc5.at.i386.rpm
Note that is for 32-bit Fedora Core 5. For a different distro, search the atrpms website for a similar package

2. Next, install the gpg key associated with the atrpms repository. If you happened to skip this step you'll see something like "NOKEY, key ID 66534c2b, Public key for ... is not installed".

Now one way to install all the rpm keys is to download them off all of the repositories websites. The downside is that it takes quite a bit of searching to find all the keys, and when you need a key it's hard to tell which repository it belongs to. Just for exemplary purposes, here's what you would run to import the atrpms key off their website:
rpm --import http://www.atrpms.net/RPM-GPG-KEY.atrpms

The way I find easier is to use the gpg utility to automatically find the keys. Unfortunately, it doesn't tie in so nicely with rpm, so the command is not as pretty. Keep in mind though, you only need to change the key id; you don't need to look up the key on the repository's website:
gpg --search-keys 0x66534c2b
gpg --export -a 0x66534c2b >66534c2b.key
rpm --import 66534c2b.key

After the key has been imported, you can delete the file exported from gpg.

3. Install the medley-package-config rpm. This one has the settings for all the other yum repositories. It comes from atrpms, and that's why we setup that one first. So run:
yum install medley-package-config

4. Install any extra keys you need with step 2. Yum will attempt to install packages you don't have keys for, and then it will give an error like "NOKEY, key ID 1aa78495". Just take that key number and substitute it into the commands from step 2. If you don't want to wait, here's a list of the keys:


atrpms66534c2b
dries1aa78495
kde-redhatff6382fa
gstreamer55f3aa6f
freshrpmse42d547b

Monday, July 25, 2005

Another code merge example

This is another example for my woven string merge algorithm. This one shows that although the merge algorithm appears to just do searches and replaces, it can match up the correct code usage.

This example is almost the same as the previous one, but another function, swap, has been added that also uses a variable named temp. There are two branches that are merged. The first branch, v2a, fixes a bug in the code by initializing temp. The other branch renames temp to total. Like in the previous example, the line temp=0 is correctly merged to total=0. The difference is that this example shows that not every instance of temp is changed. The one in swap is left unaltered.


version 1:
int sum(int *array,int n)
{
int temp;
for(int i=0; i<n; i++)
{
temp+=array[i];
}
return temp;
}

void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}



version 2a:
int sum(int *array,int n)
{
int temp;
temp=0;
for(int i=0; i<n; i++)
{
temp+=array[i];
}
return temp;
}

void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}



version 2b:
int sum(int *array,int n)
{
int total;
for(int i=0; i<n; i++)
{
total+=array[i];
}
return total;
}

void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}



merged result:
int sum(int *array,int n)
{
int total;
total=0;
for(int i=0; i<n; i++)
{
total+=array[i];
}
return total;
}

void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}

Sunday, July 24, 2005

Breaking A-List Linking

I came across a post about A-List cirucular linking from a link at Zoli's blog.

The author mentions that the top bloggers commonly link to each other, but links from us low ranking bloggers usually only go one way. He's made an offer, "I have a pretty good Google PageRank (6). Anybody that links to me, gets a return kiss in double..."

I think this is a good idea, although the topics of our blogs don't exactly match. I hope the idea catches on. Maybe I can find some more accurate link to put on my blog from the people who join in with his idea.

Sunday, July 17, 2005

New code merge example

Here's another example of my nonline-based code merge. This example merges changes from two branches. One branch renames a variable. The other branch fixes a bug and uses the variable that's renamed.


version1:
int sum(int *array,int n)
{
int temp;
for(int i=0; i<n; i++)
{
temp+=array[i];
}
return temp;
}



version 2a (temp renamed to total):
int sum(int *array,int n)
{
int total;
for(int i=0; i<n; i++)
{
total+=array[i];
}
return total;
}



version 2b (temp initialized):
int sum(int *array,int n)
{
int temp;
temp=0;
for(int i=0; i<n; i++)
{
temp+=array[i];
}
return temp;
}



merged:
int sum(int *array,int n)
{
int total;
total=0;
for(int i=0; i<n; i++)
{
total+=array[i];
}
return total;
}