Control your Music player via bluetooth

I don’t need no steenking iphone with its fancy apps. I have a fairly low end phone, a Motorola RIZR Z3 but it can run Java J2ME apps. The other day I found an awesome one that lets me control my music player MPD via bluetooth, with a nice little GUI and everything (it also apparently works for XMMS and Winamp).

I was going to twitter about it, but it is so frickin awesome that it deserves more than 140 characters about it. The app is called JAM SE and it looks like it will run on just about any phone that supports J2ME and has bluetooth.

There is a Debian package for the computer-side which makes installing on Debian/Ubuntu a doddle. For others you can grab the program from its own site Bemused-MPD bridge.

With a little bit of extra work I can even get it to control the other music playing computers in the house (all running MPD), mpdproxy on the laptop with the bluetooth connection will redirect all MPD clients to my currently active server.

It is so cool to be able to control my music playback from anywhere in the house just by whipping out my phone, geektastic. :-)

My top 10 Wordpress plugins

The following are a list of plugins I either use, have used or plan to use in the future to improve this blog.

In no particular order:

  1. Contact Form 7 – Just another contact form plugin. Simple but flexible. By Takayuki Miyoshi.

    Putting your email address on the web these days is just an invitation to be spammed to death, but it is nice for your readers to be able to contact you privately. This is a nice contact form for that purpose.

  2. Dean’s Code Highlighter – This plugin using Geshi to highlight source code in your posts. . By Dean Lee.

    If you ever put up source code snippets in your blog entries, it is far nicer to have the syntax highlighted as it is in a modern editor or IDE. This plugin provides that.

  3. del.icio.us for Wordpress – Displays your recently listened links. Based on Pownce for Wordpress by Cavemonkey50. By Ricardo González.

    Does exactly what it says on the tin.

  4. Google XML Sitemaps – This plugin will generate a sitemaps.org compatible sitemap of your WordPress blog which is supported by Ask.com, Google, MSN Search and YAHOO. By Arne Brachhold.

    Improve your search rankings by giving the search engines more information about your site, totally automatically.

  5. Sociable – Automatically add links on your posts, pages and RSS feed to your favorite social bookmarking sites. By Joost de Valk.

    Want to make it easy for readers to link your site into various social bookmarking sites. This plugin covers pretty much all of them, including some that no longer exist. :-)

  6. Twitter Tools – A complete integration between your WordPress blog and Twitter. Bring your tweets into your blog and pass your blog posts to Twitter. By Alex King.

    The plugin you need if you want twitter in your blog or vice-versa.

  7. WP Super Cache – Very fast caching plugin for WordPress. By Donncha O Caoimh.

    An essential plugin you need if your site is to have any hope of surviving a slashdotting, or even if you just want to improve performance for the ten people who visit your blog.

  8. Bad Behavior – Deny automated spambots access to your PHP-based Web site. By Michael Hampton.

    Prevent 90% of the spambots out there from even attempting to post comment spam.

  9. OpenID – Allows the use of OpenID for account registration, authentication, and commenting. Also includes an OpenID provider which can turn WordPress author URLs into OpenIDs. By DiSo Development Team.

    OpenID is what I hope will become the standard for online authentication, every site should support it.

  10. Who Sees Ads – An advanced ad management plugin that lets you decide who will see your ads, depending on user defined conditions. By Ozh.

    Want to place ads on your site but don’t want to bother your regulars (who will likely never click on them anyway), then give this plugin a try and set it to only show ads to visitors who came to your site from a search engine.

Hope these are useful. If you use some wonderful plugin I haven’t mentioned then please tell me. Adding more and more plugins until something breaks is what I do. :-)

Poor mans offsite backup

Before I got some proper offsite backup space* I used to make tarballs of files and dump them in my gmail. Not the most elegant solution but it worked and is free (I know about gmailfs, but I could never get it to work reliably).

This is the script I used to send the files:

#!/usr/bin/env python
import getpass
import optparse
import smtplib
import sys

from email import Encoders
from email.MIMEBase import MIMEBase
from email.MIMEMultipart import MIMEMultipart

opts = optparse.OptionParser()
opts.add_option(‘-u’, ‘–username’)
opts.add_option(‘-p’, ‘–password’)
(options, args) = opts.parse_args()
if len(args) < 1:
    print "Usage: send_file_to_gmail.py [-u user] [-p pass] filename"
    sys.exit(0)

if options.username == None:
    options.username = raw_input("Username: ")
if options.password == None:
    options.password = getpass.getpass()
if options.username[len(options.username)-10:] != "@gmail.com":
    options.username += "@gmail.com"

msg = MIMEMultipart()
msg[‘Subject’] = "Backup of %s" % args[0]
msg[‘From’] = options.username
msg[‘To’] = options.username

msg.preamble = "Backup of %s" % args[0]
msg.epilogue = " "

fp = open(args[0], "rb")
atfile = MIMEBase("application", "octet-stream")
atfile.set_payload(fp.read())
fp.close()
Encoders.encode_base64(atfile)
atfile.add_header("Content-Disposition", "attachment", filename=args[0])
msg.attach(atfile)

s = smtplib.SMTP()
#s.connect("localhost", "8025")
s.connect("smtp.gmail.com")
s.ehlo()
s.starttls()
s.ehlo()
s.login(options.username, options.password)
print "Sending %s" % args[0]
s.sendmail(options.username, options.username, msg.as_string())
s.close()
 

The above code is made available under the MIT license.

* While I am writing this the Dreamhost backup space I use has been down for about two weeks (it came back briefly a couple of days ago but is back down again now). I can’t complain too much as it is a free extra they throw in with the hosting package but I may have to restart my gmail sending if this keeps up.

Virgin Media are petty scumbags

For a few days now I’ve been working (a few minutes at a time) on writing a post about how to monitor your bandwidth usage using munin by directly querying your cable-modem. Today however, when I checked my nice munin graph I found it had stopped working at about 8AM. Some further diagnostic procedures revealed that the cable modem was no longer responding to SNMP requests.

After a bit of googling I discovered the reason for this is that my ISP, Virgin Media, have deliberately disabled SNMP access. Reports vary on the reasons for this, some claim “performance” others “security”, but both are utterly bogus reasons. All this does is deny customers basic information about their connection like bandwidth usage, and I can only conclude that Virgin Media want to make it more difficult for people to dispute their figures.

This isn’t enough to make me ditch VM, but it has pissed me off, and the next time I move house VM are going to be waaay down the list of providers I’ll look at.

PS. My router doesn’t support SNMP either so I can’t use that.

Who-T: Synaptics 1.1 and what your touchpad can do now

The synaptics driver. So, here’s a list of things that have changed recently with version 1.0 and 1.1.

Perhaps the most important changes have to to with auto-scaling. Synaptics obtains the touchpad dimensions from the kernel and adjusts speed, acceleration, the edges and more depending on these dimensions.

via Who-T: Synaptics 1.1 and what your touchpad can do now.

Let my kernel be Free

Playing a movie using Free driver

Playing a movie using Free driver

There has been some interesting progress on the open-source drivers for ATI graphics cards recently. It has long been a goal of mine to have a completely Free kernel, it’s why I bought this laptop rather than an NVidia-based one. I want better 3D performance than Intel can offer and was originally going to go NVidia because their Linux support was better. Then ATI released the first load of specs for their cards and I switched my preference. In the end I bought a Toshiba laptop with a Radeon Mobility 2600 graphics chip (also known as an M76 chip).

I’m not a zealot when it comes to Free software, I am a pragmatist, I use whatever works best for me. But experience has taught me that when it comes to Linux kernel code the non-free stuff is always problematic. Practically every kernel crash I’ve ever had can be traced back to some non-free driver I had in there. Who is to blame for this I’m not going to go into, there are arguments on both sides, but the fact is that if you want a completely stable Linux system you are better off keeping the kernel Free.

Of course it takes time to write drivers for something as complex as a graphics card, so up till now I’ve been using the proprietary fglrx drivers from ATI. A necessary compromise, since when I first installed Debian they were the only thing that would get X to even run. It works well enough once you learn to avoid doing the things that cause it to crash (like logging out of KDE), but it adds a hassle to upgrades (having to recompile a kernel module, which often fails and needs custom patches) and is rather finicky about its settings. I’ve periodically tested the state of the Free drivers, both radeon and radeonhd, and seen steady progress.

Today I found that they have finally reached the good-enough point where I can switch. The must-have feature for me is tear-free video playback that doesn’t cause my CPU usage to skyrocket (and hence kick the fan up to unacceptable noise levels). This means the driver needs accelerated 2D and xv support, which has now been achieved.

One quick point for anyone else wanting to switch to the Free driver from fglrx. It won’t work unless you uninstall fglrx, if you just install them side-by-side and tell X to use the Free driver it will show a corrupted image or a black screen then hang. I thought there had been a major regression until I tried removing fglrx, after which both free drivers worked perfectly.

I’m using the xserver-xorg-video-radeon driver from Debian sid, along with a custom kernel to get the required DRM support. The latest (2.6.29) kernel in sid doesn’t have the right versions of radeon.ko and drm.ko that are needed for the 2D acceleration to work. There are two ways to get these, you can either compile a new kernel using the drm-rawhide branch of Dave Arlie’s kernel http://git.kernel.org/?p=linux/kernel/git/airlied/drm-2.6.git;a=summary. Or you can just use the instructions on the X wiki to just compile new versions of those two modules.

I’m using a whole new kernel because I also want to experiment with kernel mode setting. Since radeonfb has never worked on this hardware and the best resolution vesafb can give me is 1024×768 (native res of the LCD is 1280×800), KMS is the only hope I have of getting a VT at the proper resolution.

There is no 3D support in the version of the driver I’m using, but support for that is being written as I type so I’m hopeful I won’t have to do without for long. It isn’t a huge loss for me since I only use it for playing KotOR under wine and if I get desperate I can reinstall it in Windows (I dual-boot the laptop). 3D would be good for when I switch to KDE4 but again, I can live without it for a while. I’m happy with what I have for now, and it won’t be that long before full 3D support comes along (and I won’t have to fiddle with code to get it, just aptitude upgrade).

Maintaining a Wordpress install with git

A while ago I started tracking Wordpress updates using Subversion. Instead of downloading the official release from the Wordpress website I checked out the code from the stable branch of their Subversion repo. This made upgrading as simple as running “svn up” and I didn’t lose any modifications I had made to the code.

While this worked very well it does have one big drawback, it means I can’t put the themes and plugins I use into version control since they are inside the official svn checked out dirs.

Recently I’ve been switching to git and thought that switching the Wordpress install to git would solve this problem. My first attempt was using the git-svn tool to convert the upstream subversion repo to a local git one. This would have enabled something very similar to what I was doing before with the “svn up” command, one git-svn command would have updated the code to the latest version.

The problem with that idea is that the Wordpress repo contains over 10,000 revisions. Duplicating that via git-svn would have taken days and all I really need is the current version. I looked for a while to see if there was a way to limit the number of revisions copied but apparently there isn’t.

So, I fall back to searching the web and I came across Tracking WordPress using Git, which is pretty close to what I wanted. It is a little bit more work to do the updates that way but not that much.

What I need though is an internal dev version of the site on one branch, the live site on another and the upstream code on a third. Then I need to push the live branch to my web host, and I also need to be able to pull any emergency fixes I make direct on the live site back into my local git repos. Pushing changes with git is a little tricky since a push doesn’t update the checked out files, but I found a helpful blog entry A web focused git work-flow, which gives me exactly what I want.

The one remaining problem I have is I don’t completely understand how git merges work. The internal dev branch and the live branch have some differences I don’t want merged, paths etc. Whenever I try to merge the branches though it invariably automatically changes one branch to exactly match the other and auto-commits. I’m sure git can do this, merge some changes but not others without manual intervention each time but I haven’t worked out how yet.

Okay, after a bit more time working with this setup it seems the problem is bi-directional merges. Merging from dev to live works great right up until the point I do a merge from live to dev, at which point git seems to forget that there is some stuff that I don’t want merged next time I go from dev to live. Preventing the auto-commit makes this manageable though, to do this you (confusingly) need to specify “–no-commit –no-ff”. You’d think the no-commit would be enough on its own but apparently not.

So in my local copy I have 3 branches:

  • master, the extracted Wordpress tarball
  • internal, my internal development/test site
  • external, copy of the live site

I have the following settings set on my local git repo (private details redacted) to make pushing changes easier, I don’t have to remember any parameters for the git push command.

branch.internal.remote=origin
branch.internal.merge=refs/heads/internal
remote.external.url=ssh://$USER@$HOST/~/$GIT_PATH
remote.external.fetch=+refs/heads/*:refs/remotes/external/*
branch.external.merge=external
branch.external.remote=external

Then on my web host I have the bare git repo at $GIT_PATH that gets pushed to, and the actual live site. Both of those only have the external branch.

To update the live site all I need to do is make the changes on my local copy of the external branch, then run “git push”. This sends the changes up to the bare repo, which then automatically updates the live site.

Then when a new version Wordpress gets released, what I will do is

  1. Switch to the master branch.
  2. Delete everything except the git dir.
  3. Unpack the new files to replace the deleted ones.
  4. Commit those to git and it will work out what has changed for that release.
  5. Change to the other branches in turn and git merge from the master branch.

This should update me to the latest release without losing any of my local themes, plugins or mods.

I could go one step further and create “upstream” branches for each plugin I use in a similar manner to the main upstream Wordpress branch. That would allow me to mod the plugins, and still upgrade them easily. I’m not going to do that though (yet) as I think it would be more trouble than it is worth.

KDE4 will rock

I’ve been playing some more with KDE4 v4.2 mainly Debian unstable in a VirtualBox VM, but also a Fedora 11 beta livecd on my main laptop and installed on my EeePC. The most important thing, stability, is definitely there now, it hasn’t crashed on me at all. I really could pull the trigger on the switch-over today if I had to, but I’m going to wait a little while longer. There are still some not essential but nice-to-have features missing but it is eminently usable as-is.

KDE Desktop screenshot

KDE Desktop screenshot


All the hardware I’ve been testing with has had either no 3d-acceleration, or practically none in the case of the EeePC. I was hoping that VirtualBox’s new opengl acceleration feature would let me use some of the desktop effects but while it is apparently sufficient to run compiz it is no enough to handle KDE4s effects. :-( So I have yet to experience the full-on KDE4, and won’t until I make the switch proper.

Network-Manager Plasmoid

Network-Manager Plasmoid


To control Network-Manager there is no stable tool, but there is a plasmoid in Debian experimental. It works for the most part, but sometimes playing with the settings can make it crash. Not critical since it restarts automatically and the underlying network connection isn’t affected by the crash.

There is no bluetooth support yet, not a deal killer, but I do use it to sync my phone contacts and transfer the odd file so I’d like to wait till something is in place for that. I saw some mentions of bluetooth in the Fedora GUI, but couldn’t get it to actually talk to anything. That might be due to the wireless switch on my laptop though, as it has both a hardware and software switch which both need to be enabled to make bluetooth transmit.

Both in my VM and on my EeePC sound did not work out of the box unfortunately. No matter what I did to try and configure Phonon, which is the replacement for ArtsD in 4, it just wouldn’t output any sound. In both cases the fix was to install the xine backend to replace the gstreamer one. After which sound worked perfectly.

When I booted the Fedora live CD the sound did work out of the box, but when I looked what it had done differently, I found that it was using the xine backend by default. The conclusion I’m drawing here is that gstreamer is shit.

Lancelot launcher menu

Lancelot launcher menu


I’ve found Lancelot to be excellent, once I realised you can resize the menu. Lancelot is an alternate to the regular “Start menu” style launcher. While the normal launcher has also been altered to a new style I don’t like it so much. If you are trying out KDE4 I’d suggest giving Lancelot a go, I think it is the better of the two. Both have built-in search, but the mechanism of navigating the tree works better in Lancelot.

The slide mechanism in the main launcher means that when you’ve gone into the wrong branch and want to back up one you have to move to the far left and click a little line that is a back button. In contrast in Lancelot you can still see the previous level in the tree and so it is much easier to recover from mistakes (of which I make many).

It still doesn’t work so well when there are too many entries on one page, having to grab the scrollbar and scroll is unacceptable. I’ll have to either edit the menus to prevent that or find some way to shrink each entry so more can fit at once. I don’t really need the double line entries with the description, the app name is enough for me.

And for those who don’t like either and want the old start menu back, an applet for that is still there too.

Trash Settings window

Trash Settings window


Date-based deletion of items in the Trash is an excellent idea, if that means what I think it means. I’m hoping it means that regardless of how much is in the Trash an item will be deleted permanently after $TIME_PERIOD of being in there. That will satisfy the OCD part of me that can’t stand the disk being used up by stuff I don’t need any more.

As I’m intending to use the GUI as my primary interface when I do the switch for real, in large part for the safety net that the Trash can gives you it is important that it operate correctly. I hate the implementation on Windows where the Trash is practically always full. I end up manually emptying it at least once a day, which removes a lot of the point. I need to wait for a few days to confirm it works how I hope.

Dolphin file browser

Dolphin file browser


Dolphin works well, I much prefer having separate apps for file-browsing and web-browsing. Combining the two in Konqueror always felt confused. I don’t want to see my web bookmarks when I’m looking at my Music/ dir, but hiding them meant losing them when I was browsing the web. Now I can just keep Konqueror for the web and Dolphin for local, much neater in my opinion. The preview feature seems to slow things down too much for my taste, but I’m sure that can be switched off somewhere. I just haven’t looked for that setting yet.

Browsing in general is a little slow, but I’m putting that down to being on slow or virtual hardware. On a decent machine I’m betting it will be snappy enough, I hope.

The Dragon player that comes with it seems dreadful, that will have to go. Particularly on the Fedora boot where it couldn’t play anything on my system due to not having any codecs installed. I presume it had the OGG Theora codec, but who has videos in Theora format laying around? I’ll need a KDE4 or QT4 based GUI for mplayer, or at worst I’ll fall back to using the command-line for launching videos.

Of course the biggest reason to upgrade to v4 is the revamped patience card game which can now play the 3-card variant of Klondike! :-) I’m looking forward to the day when I’ll be running KDE4 on free ATI drivers with KMS, and that day is within sight.

Convert files to UTF-8

I occasionally come across text files with weird squiggles or numbers in them were there should be characters. Usually it’s accented characters, but in extreme cases I’ve seen it happen with speech marks.

The problem of course is that the files are not ASCII, and text files don’t store what character set they were created with. So if the set my system happens to use doesn’t match the one the file uses then the result is screwed up letters.

To solve this I created a little python script that converts the file into using the UTF-8 character set as that is nice and universal. You can specify what codec the input is in with the -c option, if you don’t bother then it assumes the Windows 1252 codepage as that is usually what it is in my experience. There is also a force option for when the conversion comes across characters that don’t match the input codec but you want it to convert anyway.

I thought about making it autodetect the codec of the input file, but it is a lot of work for little benefit. The current code works in 99% of cases for me.

#!/usr/bin/env python

import codecs
import optparse
import sys

if len(sys.argv) < 2:
    print ‘convert_cp1252_to_UTF-8.py [-f] $filename’
    sys.exit(0)

opts = optparse.OptionParser()
# ‘help’, ‘config=’, ‘logfile=’
opts.add_option(‘-f’, ‘–force’, action=’store_true’)
opts.add_option(‘-c’, ‘–codec’, default=‘cp1252′)
(parsedOpts, args) = opts.parse_args()
filename = args[0]

try:
    if parsedOpts.force:
        textfile = codecs.open(filename, ‘r’, encoding=parsedOpts.codec, errors=‘ignore’)
    else:
        textfile = codecs.open(filename, ‘r’, encoding=parsedOpts.codec)
    utffile = codecs.open(filename+‘.utf-8′, ‘w’, encoding=‘utf-8′)
    utffile.write(textfile.read())
except:
    print ‘Error converting to UTF-8, source file probably doesn’t use cp1252

The above code is made available under the MIT license.

I need an idiot-proof shell

After decades of never losing any significant data, last night I deleted my Video dir for the second time in six months, along with my Music this time. Fortunately I had learned my lesson and had a complete backup this time. The first time I lost a large amount of non-critical videos I had downloaded off the internet (okay, it was porn. I said it, happy now?). This time I just lost a couple of episodes of This Week in Fun I hadn’t watched. If I can be bothered I can easily re-grab them from ODTV.

I’m not sure how I accidently deleted the stuff, I was moving my config files from being stored in Subversion to git, using this method. I must have accidently rm -rf them somehow. This is my problem, it’s incredibly easy to shoot yourself in the foot from the command-line.

I’ve always used a combination of the GUI and shell, my first proper computer was an Amiga 500+ which, while it had an amazing modern GUI while Windows was still stuck with 3.1, also had a pretty good shell interface. Not quite up to unix standards, but much better than DOS. So I’ve always used both, depending on what was easiest for the task.

When I switched to Windows (after my last Amiga died on me), I started using the GUI much more heavily since DOS is so underpowered. When a short time later I switched to Linux though that got reversed since the Linux GUI at the time wasn’t so hot and the shell was incredibly powerful. So I currently default to using the shell, which makes me nice and productive but also means I’m working without a safety net.

If recent experience is anything to go by, I either need to start relying on the GUI much more or I need to find myself an idiot-proof shell. Since I don’t think the latter is possible it looks like I’ll be GUI-focused from now on. This is going to be a hard transition for me, much like giving up a narcotic, but I think it is necessary.

I’m going to start this transition at the same time as I install KDE 4, which is looking excellent in my tests on my EeePC by the way. I could almost transition now, there are just a couple of things (that are in the works) that I need before I can convert. A Network-Manager controlling plasmoid being the main one.

That way I only have to relearn how to do things in one GUI, rather than learning how to do it in KDE 3.5 and then a new way in 4. I’m not going to give up the shell completely mind, just change my balance so it is 80/20 in favour of the GUI instead of the other way round.

Wish me luck.