How to convert from WMA to MP3

Converting Windows Media Audio files into MP3 format is rather easy with mplayer and lame. My car stereo plays MP3s, so WMA is of no use to me!
This code is based on this script but I have to wonder why they overwrote the wma file?
Piping the output of mplayer into lame is left as an easy lesson for the reader!
for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader "$i" && lame -m j -h --vbr-new -b 160 audiodump.wav -o "`basename "$i" .wma`.mp3"; done; rm -f audiodump.wav

Linux: Auto-mounting USB camera memory

I have 2 cameras. One takes Flash cards, the other takes SD cards. If my Sony still worked, I’d also add memory sticks to that list.
I’ve got a routine, a workflow, for copying photos off camera media but it’s slightly more complicated with multiple memory types!
Kevin Lyda kindly mailed me a script he had for auto-mounting his camera and copying the files off. It uses the usb hotplug program to do that but I couldn’t get it to work with my card reader so I wrote the following script. Bits of it are from Kevin’s scipt, so thanks!
I insert my camera media, and run “copyfromcamera.sh” and it find the Flash card and copies all files off it into a directory with today’s date!

Make sure you have your media mount points setup in /etc/fstab. Here’s what mine looks like:

----------/etc/fstab----------
/dev/sdb1 /mnt/cfcard vfat users,noauto,rw,uid=1000 0 0
/dev/sdd1 /mnt/sdcard vfat users,noauto,rw,uid=1000 0 0
----------/etc/fstab----------

Copy and paste this into a file and save it to /usr/local/bin/copyfromcamera.sh and make it executable (chmod 755 /usr/local/bin/copyfromcamera.sh)

----------/usr/local/bin/copyfromcamera.sh----------
#!/bin/sh

export YEAR=`date +%Y`
export TODAY=`date +%Y-%m-%d`
export DIR=/home/donncha/Photos/$YEAR/$TODAY/
mount /mnt/cfcard/ 2> /dev/null
if [ -d /mnt/cfcard/dcim/ ]; then
    mkdir -p $DIR
    find /mnt/cfcard/dcim -type f -print0 | xargs -0i mv -vi '{}' $DIR
    umount /mnt/cfcard/
    df -h
fi
mount /mnt/sdcard/ 2> /dev/null
if [ -d /mnt/sdcard/dcim/ ]; then
    mkdir -p $DIR
    find /mnt/sdcard/dcim -type f -print0 | xargs -0i mv -vi '{}' $DIR
    umount /mnt/sdcard/
    df -h
fi
----------/usr/local/bin/copyfromcamera.sh----------

Spreadsheet Templates

Every now and again I need to dig into Open Office to create a document, be it a report, or a spreadsheet.
Thankfully Linux has been able to read Word and Excel files for some time as that’s what the world and it’s dog use!
Anyway, I needed an invoice template, and came across these Open Office extras listing lots of templates for Writer, Calc and Draw. Several very useful examples there too!
Here’s a few sample reports in PDF format. Obviously it’s harder to edit, but at least they’ll provide for inspiration when creating your own documents!

Simple MySQL Backup

If, like me, you have a database full of small tables, but all amounting to a large amount of data then dumping the data from it into a single file is handy, but not very useful when it comes to retrieving a backup of one single table.
Instead, wouldn’t it be easier to dump each individual table into it’s own file? What about keeping a week’s worth of backups? Here’s one way I backup my WordPress db with a little Bash script:

export d=`date +%u`
mkdir -p backup/$d
for i in `echo "show tables" | mysql -u username -ppassword database|grep -v Tables_in_`;
do
  echo $i; mysqldump --add-drop-table --allow-keywords -q -a -c -u username -ppassword database $i > backup/$d/$i.sql
  rm -f backup/$d/$i.sql.gz
  gzip backup/$d/$i.sql
done

Struggling to Manage Your Ever-Growing Digital Photo Collection?

In this (what looks like a promo) article John Grand explains some of the issues with organizing your photos.
After reading this I went looking, and found Lodju (also available from Debian – apt-get lodju), and then looked into gThumb. It allows you to put photos into categories, and I spent an hour last night sorting some of my snaps! I backup to DVD almost once a month so hopefully my photos are reasonably safe! Now, if only gThumb would remember when I rotate my images! I don’t want to modify the originals, but having a rotated thumbnail would be great. Lodju does it!