Interactive storefront display | ARvertising news

As you walk down the street you are approached by a dog. He is on his guard trying to discern your intentions. He will follow you and interpret your gestures as friendly or aggressive. He will try to engage you in a relationship and get you to pay attention to him.

from Interactive storefront display | ARvertising news.

Computer generated dog, reacts to real-world passers-by.

How to Correctly Open a Banana

So, it turns out me and everyone I know have opened a Banana the wrong way our entire lives. I have always thought that banana’s could only be opened that one way and always been rejecting any other way of doing it. But the living learn and me included. When I watched this the first time I thought to myself that this guy has to be joking. What’s the joke in the whole clip…but how wrong I was. It actually turned out to be a much more efficient way of pealing the banana to get to the actual fruit.

from How to Correctly Open a Banana – Monkey… « Bit Rebels.

Ruby Mock Web Server

I spent the afternoon today working with Sarndeep, our very smart automated test guy. He’s been working on extending what we can do with rspec to cover testing of some more interesting things.

Last week he and Elliot put together a great set of tests using MailTrap to confirm that we’re sending the right mails to the right addresses under the right conditions. Nice tests to have for a web app that generates email in a few cases.

This afternoon we were working on a mock web server. We use a lot of RESTful services in what we’re doing and being able to test our app for its handling of error conditions is important. We’ve had a static web server set up for a while, this has particular requests and responses configured in it, but we’ve not really liked it because the responses are all separate from the tests and the server is another apache vhost that has to be setup when you first checkout the app.

So, we’d decided a while ago that we wanted to put in a little Ruby based web server that we could control from within the rspec tests and that’s what we built a first cut of this afternoon.

require File.expand_path(File.dirname(__FILE__) + "/../Helper")
require 'rubygems'
require 'rack'
require 'thin'
class MockServer
  def initialize()
    @expectations = []
  def register(env, response)
    @expectations << [env, response]
  def clear()
    @expectations = []
  def call(env)
    #puts "starting call\n"
    @expectations.each_with_index do |expectation,index|
      expectationEnv = expectation[0]
      response = expectation[1]
      matched = false
      #puts "index #{index} is #{expectationEnv} contains #{response}\n\n"
      expectationEnv.each do |envKey, value|
        puts "trying to match #{envKey}, #{value}\n"
        matched = true
        if value != env[envKey]
          matched = false
      if matched
        return response
    #puts "ending call\n"
mockServer =
mockServer.register( { 'REQUEST_METHOD' => 'GET' }, [ 200, { 'Content-Type' => 'text/plain', 'Content-Length' => '11' }, [ 'Hello World' ]])
mockServer.register( { 'REQUEST_METHOD' => 'GET' }, [ 200, { 'Content-Type' => 'text/plain', 'Content-Length' => '11' }, [ 'Hello Again' ]]), :Port => 4000)

The MockServer implements the Rack interface so it can work within the Thin web server from inside the rspec tests. The expectations are registered with the MockServer and the first parameter is simply a hashtable in the same format as the Rack Environment. You only specify the entries that you care about, any that you don’t specify are not compared with the request. Expectations don’t have to occur in order (expect where the environment you give is ambiguous, in which case they match first in first matched).

As a first venture into writing more in Ruby than an rspec test I have to say I found it pretty sweet – There was only one issue with getting at array indices that tripped me up, but Ross helped me out with that and it was pretty quickly sorted.

Plans for this include putting in a verify() and making it thread safe so that multiple requests can come in parallel. Any other suggestions (including improvements on my non-idiomatic code) very gratefully received.

Throttling Flickr Uploads

I’m part way through uploading a substantial backlog of photos (11,000+) to Flickr.

I had started out trying to go through them and decide which were worth uploading and which weren’t, but that approach was taking far too much time. I needed some help. So I decided that I’d upload all of them and open them up to my family to help with the sorting – asking them to tag the photos with the people in them and also use tags like "TODELETE" to mark those that are just noise and should be thrown out.

I could have opened the net wider, but there are photos of my kids and other people’s kids in there so just family it is.

I’m using phpFlickr to batch upload photos to Flickr and my script uploads as fast as the bandwidth will allow, though admittedly single-threaded. This meant that I couldn’t use it at work, at least not with a clear conscience, so have been uploading from home only. Those 8+ hours a day in the office have been bugging me though, so I was looking for a way to have photos uploading without having a detrimental impact on our connection.

A little googling found an article on bandwidth throttling in OSX that showed the basics of using ipfw to limit transfer rates. A bit of tweaking and I ended up with

sudo ipfw pipe 1 config bw 128KByte/s
sudo ipfw add 1 pipe 1 dst-ip

This limits the upload traffic to to 128KB/s and means I’m not going to cause anyone a problem.


Moving Stuff Finished :-)

Yesterday evening I followed the excellent instructions from the WordPress Codex on Migrating from Movable Type to WordPress. This proved to be extremely easy with all the posts, categories and comments coming through perfectly.

I had some files (photos, ppt etc) manually uploaded, so logged in to move those over. As well as migrating I moved the blog from /blog/ up to the root of the site. That all went swimmingly and I picked a nice shiny new theme called demar.

The only thing left was to sort out redirects for all the old links – so I don’t lose all the link love I’ve managed to build up over the years.

After reading through the various options I had a few issues. I’d tinkered a bit with the MT URLs in the past and had a lot of legacy stuff hanging around. I decided I’d just do it with apache’s .htaccess. Not a choice for everyone, but my regex skills aren’t too shabby, so I figured I’d start there.

The URLs fell into a few different patterns:

/blog/atom.xml, index.xml, etc – the feeds. For now these can all redirect to /feed/ so we start with

RewriteEngine On
RewriteRule ^blog/atom.xml$ /feed/ [L,R=301]
RewriteRule ^blog/index.rdf$ /feed/ [L,R=301]
RewriteRule ^blog/index.xml$ /feed/ [L,R=301]

Feeds dealt with I moved on to the root of the blog, adding

RewriteRule ^blog/$ / [L,R=301]
RewriteRule ^blog$ / [L,R=301]

and then onto the archives, where we start to get trickier. First we have categories which take the form /blog/archives/cat_somewhere_I_put_stuff.html. WordPress creates a different pattern by default – /categories/somewhere-i-put-stuff. Not too hard, first we pull out the words, then glue them back together again.

RewriteRule ^blog/archives/cat_([^_]*)_([^_]*)_([^_]*)_(.*)\.html$ /category/$1-$2-$3-$4 [L,R=301]
RewriteRule ^blog/archives/cat_([^_]*)_([^_]*)_(.*)\.html$ /category/$1-$2-$3 [L,R=301]
RewriteRule ^blog/archives/cat_([^_]*)_(.*)\.html$ /category/$1-$2 [L,R=301]
RewriteRule ^blog/archives/cat_(.*)\.html$ /category/$1 [L,R=301]

Each of these regexs pulls out categories of 4 words long, 3 words, 2 words and 1 word respectively. If you have categories with more words in then you’ll need to add longer versions of these, ordering them longest first.

Next the monthly archives, in MT /blog/archives/2004_04.html and in WP /2004/04/

RewriteRule ^blog/archives/([0-9]{4})_([0-9]{2})\.html$ /$1/$2/ [L,R=301]

easy enough.

Then we have the individual posts. These fall into two groups, name based files and numbered files. The name based files are all /blog/archives/categoryname/postname.html. I had thought these were going to be a pig, but I discovered completely by accident that if you simply use the postname part of that then WordPress figures out which post you meant and redirects to its nice new WP URL. Sweet.

RewriteRule ^blog/archives/[^/]*/(.*)\.html$ /$1 [L,R=301]

The exception to this turns out to be posts that have a hyphen in the name. MT strips the hyphen, leaving WP with a name that doesn’t match. I put a rule in specifically for the one post I have that was affected:

RewriteRule ^blog/archives/personal/beijing_sightse.html$ /2008/05/04/beijing-sight-seeing/ [L,R=301]

Which just leaves the numbered posts: /blog/archives/000217.html. The numbered entries proved to be tricky. While you can just append the number /1234 like so and WordPress will fid a post for you, the posts weren’t matching up. As many of these had been indexed by Google and linked by others I wanted to hook them up to the right posts.

Fortunately I had Movable Type still rendering my site as static HTML files, so with a quick bit of bash magic I pulled out the numbered posts and made rules to map them to the Movable Type post name based permalinks (which we already did rewrite rules for above):

find . -type f \
| grep "^\./[0-9]*\.html$" \
| xargs grep permalink \
| awk ‘{print $1 " " $17}’ \
| sed -e ‘s%^\./%RewriteRule ^blog/archives/%’ \
-e ‘s%\.html:%.html$%’ \
-e ‘s%href="’ \
-e ‘s%">Permalink</a><br%%’ \
> rules.txt

Each line of rules.txt ends up looking like this

RewriteRule ^blog/archives/000285.html$ /blog/archives/semantic-web/vocabs.html [L,R=301]

which results in a second redirect to just /vocabs and then a third as WP works out where to take you finally. Not great to be bouncing around so much, but much better than losing the link.

Good luck if you decide to make the same move.

Flickr Bashing

I spent some time a little while ago writing a bash interface to the Flickr api, using curl to handle the http interactions.

I was doing it because I have a backlog of around 11,000 photos that need sorting and uploading. To get them backed up I decided to simply upload them all marked as private and tagged as ‘toProcess’ so that I could then start to go through them online.

I’d written most of the raw bash scripts to do the job, but hadn’t put enough error handling in, or enough testing, to trust them with my live flickr account.

That was back at Christmas, so coming back to it fresh a thought occurred to me. At work we’ve been working with php a lot, and php works just dandy as a command line scripting language as well as a web language. Not only that, but php also has a great Flickr library already, it’s tested and in production use – phpFlickr by Dan Coulter.

So, with all my photos already organised in folders…

$path = ini_get(‘include_path’);
$myPath = dirname(__FILE__);
ini_set(‘include_path’, $path . $PATH_SEPERATOR . $myPath);
ini_set(‘include_path’, $path . $PATH_SEPERATOR . $myPath . DIRECTORY_SEPARATOR . ‘phpFlickr-2.2.0’);
require_once ‘phpFlickr.php’;
$f = new phpFlickr(‘your api key here‘, ‘your secret here‘);
$f-&gt;setToken(‘your token here‘);
$searchPath = $myPath.DIRECTORY_SEPARATOR.’later/’;
$uploadDir = opendir($searchPath);
$is_public = 0;
$is_friend = 0;
$is_family = 0;
while (false !== ($listing = readdir($uploadDir)))
$isHidden = ((preg_match(‘/^\./’, $listing)) &gt; 0) ? true : false;
if (is_dir($searchPath.DIRECTORY_SEPARATOR.$listing) && !$isHidden)
echo $listing."\n";
$year = (preg_match(‘/[0-9]{4}/’, $listing)) ? substr($listing, 0, 4) : null;
$setName = $listing;
$setDir = opendir($searchPath.DIRECTORY_SEPARATOR.$listing);
$tags = "$year \"$setName\" toprocess";
while (false !== ($setListing = readdir($setDir)))
$isJpeg = ((preg_match(‘/\.jpg$/i’, $setListing)) &gt; 0) ? true : false;
if ($isJpeg)
$photoFilename = $searchPath.DIRECTORY_SEPARATOR.$listing.DIRECTORY_SEPARATOR.$setListing;
$response = $f-&gt;async_upload($photoFilename, $setListing, ”, $tags, $is_public, $is_friend, $is_family);
echo $response."\t".$photoFilename."\n";
rename($photoFilename, $photoFilename.’.done’);
stream_set_blocking(STDIN, FALSE);
$stdin = fread(STDIN, 1);
if ($stdin != ”)
echo "Exiting from stdin keypress\n";

This script wanders through the folders uploading any jpegs it finds, tagging them with the name of the folder they came from as well as a year taken from the first four digits of the folder name. All so simple thanks to Dan Coulter’s work.

Fixing a plasma TV

My father-in-law very, very kindly donated me a plasma TV recently, a 32" Phillips from a few years ago. It was refusing to switch on, the power LED on the front of the screen indicating what the manual calls "protect" mode. This means that the TV has a fault and the LED shows it by blinking red.

Finding information about stuff like this online is always annoying difficult due the variance in search terms. Is that LED blinking, flashing, cycling, going on and off or any of a number of other descriptions. I found several references to this problem on a mix of forums, but eventually found a thread describing how to fix a phillips plasma tv with a flashing red led on avforums.

From there I managed to find that the type of TV I have is covered by the FM23 AC Service Manual, available here in the annoying form of a 16 part rar file which unrars to a single PDF.

Most of the successes in the thread seemed to have come from following Barbusa’s instructions in the thread linked to above, detailing three capacitors that wear out on the main power board. Diagnosing this was based rather loosely on the fact that if I kept switching it off and back on every time it went into protect it would eventually power up and run just fine. I’m guessing that this comes from the caps managing to build up enough charge over several power cycles.

Capacitors like these are really cheap to replace, I bought some from a local Maplin for the grand total of £1.14. I also bought a new soldering iron, a fine tipped butane one as Barbusa recommended for the job, bringing the bill to a lofty twenty quid – far less than I’d have to pay just to get someone to look at it for repair.

Armed with these new caps and the stupidity necessary to play at soldering inside a high voltage appliance I started stripping it down. Lying the screen flat on its front (on something soft) to remove the stand and screws from the back panel which gives us a great view of the insides – click for larger images.


In the middle here I’ve outlined the main power board, it’s the one with big capacitors, transformers and the two really big metal heat sinks (one black, one silver) running up the middle of the board.

power board connectors

To remove it, we first have to disconnect all the connectors, I took a few photos so I could put them back, but it seems the cabling routes and different sizes of connectors means that they will only fit one way. There are several screws all around the edge and one in the middle of the board, there a small torq fitting, the same as the case screws not sure what size these are, but they’re the smallest torq I’ve got in my toolbox.

power board capacitors

Having removed the board we need to find capacitors 2662, 2663 and 2664. In my 32" screen 2662 is a 1000μF 25v 85°C with 2663 and 2664 both 25v 100μF 25v 85°C. I took Barbusa’s advice and bought 105°C rated caps to deal better with the heat. For 2663 and 2664 I couldn’t get the 25v caps, so bought the higher rated 50v ones that are fitted in the 42" plasmas. I’m no expert, but thanks to some friendly advice in #electronics on I was confident they would be safe.

Capacitors 2662, 2663 and 2664

Finding them is easy enough, the board is numbered, so with fingers on the capacitor and my new soldering iron on the joints I slowly pulled the caps out and replaced each one in turn.

underside of 2662, 2663 and 2664

The numbering is on both sides of the board, here I have replaced 2662 and I’m just about to replace the other two.

Carefully putting everything back together – deep breath – it all works, powering up first time and running fine. Many thanks to the help of strangers :->