eightbitraptor.com Rawr.

Pleased it is nearly food o clock.

Android Development without Eclipse

I started having a bash at some Android programming recently, nothing amazing, just flexing the old Java muscles again (for the first time since university, back when you had to avoid the Velociraptors to get to lectures), and it’s actually pretty fun.

What’s not fun however is the behemoth that is Eclipse. I swear, before I got fed up and threw it away, I spent longer bashing my head at Eclipse than I actually spent setting up the toolchain, writing some code and getting it on my phone.

Whilst the Android developer website is amazingly helpful I thought it might help to have a quick reference to get started. And the most important step is to download the sdk from here, unzip this to a directory where it isn’t going to get in your way, I use ~/code/android-sdk and add ~/code/android-sdk/tools to your path.

The next important thing is to install the SDK components for whatever android version you’re using and create an Android Virtual Device to use in the emulator. This is all covered in the Android install guides and when your done you should be good to go at creating a project.

The basic workflow is this:

Note: If you are reinstalling a new version of your app you’ll need to add the -r flag to android install otherwise it will whinge that the app apready exists.

The steps to getting your app on an actual phone are pretty much the same however:

and breath a breath of fresh air at being able to use $EDITOR to make cool things again.

posted on July 27 2010, and tagged with android programming java cli

RSS Awesomeness, Creating feeds with Sinatra & Builder

So I was reading the Design Monkey blog this evening and suddenly a vast sense of inadequacy welled up inside me. Was it because I had such vastly inferior design skills? Or maybe far less comical writing ability?

Hell No.

The design monkey provides that most awesome of things (as I’m sure do many others), an RSS feed of his eloquent prose, so not to be outdone and armed with the best of tools, I set out creating one with Ruby, builder and Sinatra

This turned out to take about 10 minutes and be amazingly less impressive than it sounds but here goes anyway. First you should create a builder template for your RSS feed. Mine looks like this:

  xml.instruct! :xml, :version => "1.0"
  xml.rss :version => "2.0" do
    xml.channel do
      xml.title "eightbitraptor"
      xml.description "The personal blog of developer, music lover and recovering sysadmin Matt House"
      xml.link "http://eightbitraptor.com/posts"

      for post in locals[:posts]
        xml.item do
          xml.title post.title
          xml.description to_html(post.body)
          xml.pubDate pretty_date(post.published)
          xml.link post_url(post)
        end
      end
    end
  end

This is saved in my views folder as feed.builder so that in my main Application I can define my route like so:

  get '/feed.xml' do
    builder :feed, :locals => { :posts => Post.all }
  end

Where a Post class does all the magical awesome (but is essentially just a way of grouping together titles and bodies as referenced in the builder template).

And that is pretty much all you need to do to generate functional rss feeds with Sinatra. If you want to dig deeper, especially into what my mystical Post object is, then the code is on github as per usual.

Get the source

posted on July 26 2010, and tagged with ruby programming

Running MPD on OSX

After finally getting fed up and giving iTunes the boot, I got round to making MPD work on my Mac. and unfortunately, apt-get install it ain’t!

First step is to actually get hold of and install mpd, if you’re using sensible and using homebrew that’s as easy as:

brew install mpd

Which will pull in all of the required dependancies and compile them all for you. Then comes the mpd config file. This is all pretty standard stuff, you can adapt from the standard and massively verbose example included with the mpd sources. Mine lives at /usr/local/Cellar/mpd/0.15.9/share/doc/mpd/mpdconf.example. The stuff you need to care about is:

music_directory
playlist_directory
log_file
db_file
pid_file

mixer_type "software"

Make sure these paths are all writeable by the user that you intend to run mpd as. In my case, I run mpd as the mpd user, and I made the mpd user and my normal user account members of group mpd.

What this amounts to is a music and playlist directory that the mpd user can read from and that I can add songs to. If you run a multi user system it’s probably a good idea to put this somewhere outside of your home dir.

A special point regarding the mixer_type line: I have found this necessary when running on Snow Leopard to avoid mplayer crashing hard when trying to skip playing tracks, but as is normal with these things YMMV.

Once this has been set up you should be able to start mpd with

mpd --create-db

and watch it chug away for a while depending on how much music you have.

Client

I use the excellent Theremin, which is an OSX native MPD client and does the job admirably. If that’s not your style there are an excellent array of decent mpd clients out there.

Last.fm

Last fm Scrobbling is acheived by the use of the lastfmsubmitd daemon, and it’s built in client lastmp. It’s dead easy to set up. Clone the sources from Github and follow the instructions in the INSTALL file. The client scrobbler lives inside the contrib folder of the checkout.

I installed lastfmsubmitd to /usr/local/bin and created it’s config file, and then simply copied the contrib/lastmp script to /usr/local/bin.

One gotcha if you’re not familiar with running Python stuff (I’m not) is that lastmp will bail out complaining it can’t import libmpdclient2. this is easily fixed with:

easy_install py-libmpdclient2@

which will ramble on about installing eggs, I guess these are pythons equivalent of gems.

Both of these daemons apparently need to be running to actually make scrobbling happen so I normally wrap these up in /usr/local/bin/music_starter, which looks like

  #! /bin/sh
  /usr/local/bin/mpd && \
  /usr/local/bin/lastfmsubmitd && \
  /usr/local/bin/lastmp

Tying it all together

You can start the whole kit and caboodle on boot by creating the following plist file and adding it to launchctl:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Disabled</key>
	<false/>
	<key>Label</key>
	<string>com.eightbitraptor.mpd</string>
	<key>Program</key>
  <string>/usr/local/bin/music_starter</string>
</dict>
</plist>

I put this in /Library/LaunchDaemons/com.eightbitraptor.mpd.plist. Add it to launchd and start it like this:

sudo launchctl load -w /Library/LaunchDaemons/com.eightbitraptor.mpd.plist
sudo launchctl start com.eightbitraptor.mpd.plist

And Job done! Now you too can get rid of stinking iTunes. Now all that’s left is to find something comparable to “mp3tagedit”:

posted on July 21 2010, and tagged with sysadmin music