First post from my Transformer Prime

Cheryl bought me a Transformer Prime for my birthday. It arrived yesterday and I went home during my lunch hour to plug it in so I could use it sooner.

It feels really nice to hold, and the keyboard makes a big difference when I have a lot of text to input like this. I would probably have finished writing stuff if I was using a virtual keyboard.

Android still lacks many good apps designed to work on such a big screen, bit I’m sure there will be more than enough over time. I’m happy with using the phone-style interfaces for most stuff and then taking advantage of the big screen for pictures, videos, web browsing and stuff like that.

So yeah, my first impressions are good, and I’m sure the experience will get better and better.

New job

Since Cheryl was looking like getting a job in London I’ve been looking for one myself. I sent an application to LoveFilm after thinking about how much of a good fit it would be for my interests. They’re a Perl house, so I know the language. They’re a company that deals with films, which I spend a lot of time and money on. The Playstation 3 app kind of made my mind up because I thought that it would be something I would like to work on.

I had to complete a programming test before anything else. After doing that I thought that I hadn’t done very well, but apparently I was worrying over nothing. I was offered an interview last Friday and so I went out and bought a new suit, got a haircut, had a shave, and went down there.

The interview itself went pretty well. I had a technical test/interview with two of the developers there, and then I had an interview with the head of the digital distribution team. I felt fairly comfortable during most of this process. The only issue was the pressure of being tested on programming stuff without a computer nearby. I don’t like writing SQL on paper. I much prefer to try a query once, then adjust it if it’s wrong, but oh well.

After the interview I was told that I should hear back fairly soon, so I went away not knowing what would happen, or how long it would really take.

I met up with JonP and we went for some drinks before my train at 20:30. At around 20:15 we realised that there was no chance of me making the train to Nottingham, so JonP offered to let me stay at his. We left the Bull in Shepherd’s Bush and went to the London Cocktail Club for a couple of drinks. Then we headed to Soho to a weird bar that serves drinks infused with garlic and stuff. We each had a shot of tequila infused with chilli. It was disgusting, so we chased it down with a beer.

On the way out of that bad JonP realised that he no longer had his bag. We headed back to the London Cocktail Club, which was closed. JonP rang their phone and left a message while I banged on the shutter door. Eventually someone came to the door to clean the steps with a mop, and thankfully JonP’s bag was still in there.

We caught a bus back to JonP and Emma’s apartment and I fell asleep fully suited up. I woke up a few times the next morning, then eventually noticed that I had a missed call from my contact at the agency. He said he’d got some feedback for me, and asked me to call him when possible.

I called him back and he told me that the interview was positive and that I had been offered the job. ๐Ÿ˜€

I rang Cheryl and my immediate family to let them know how it went, and started to feel pretty happy.

We decided to go and get some Mexican breakfast at Wahaca. JonP got as far as the DLR station before he decided to go back home to sleep. Emma and I powered on through. We decided to begin the drinking straight away. We ordered a tequila and a Corona, and during the course of eating our lunch we also ordered another tequila.

At about 2:30 Emma had to go to meet some of her friends so I decided to wander around London on my own for a while.

Cheryl called just as Emma left and said that she was thinking of coming down to London for the night. We discovered that the coach would be much cheaper, and Emma and JonP were fine with it, so we made plans.

I decided that I wanted to read a book and enjoy the day. I bought A Room with a View by E. M. Forster and made myself comfortable in Costa Coffee. I was reading in there for about 4 hours while Cheryl made her way to London. JonP’s band were playing a gig in Camden so we arranged to meet over there. I set off for Camden and met Cheryl at the tube station. She’d just seen JonP walk by with his guitar, so we headed off looking for the pub.

The venue was pretty small and incredibly warm, but the gig itself was good. ๐Ÿ™‚

After the gig we went back to JonP’s apartment and Emma was asleep on the couch. She woke up after a little while and went to bed instead. We stayed up and had some pizza and stuff from Pizza Planet, and then called it a night.

We left fairly early on Sunday so that we could have some of the weekend chilling out at home. It was a really good weekend. ๐Ÿ˜€

Problems with LOVEFiLM on PS3

I recently subscribed to LOVEFiLM again because I saw that I could stream movies to my PS3. I was mostly pleased with how the application worked initially, but now I’ve been using it for a while there are a few things that bother me about it.

A-Z should mean A-Z
When you view a genre of movies you can view the most popular ones, the highest rated ones (usually pretty much the same list), or you can choose to view the entire genre A-Z. I decided I wanted to view all of the comedy movies on there to look for something a bit less popular. I scrolled down until I reached somewhere in the B section of the list and then it stopped scrolling. The problem is that the application only lets you view 100 movies in a list. No more get added to the list when you near the bottom, and there’s no pagination at all. This means you have to search for a film specifically if its title comes after the beginning 2 letters of the alphabet and it’s not in the popular/highest rated lists. That brings me neatly to my next gripe.

Searching is clunky
Rather than use the PS3 system keyboard there is a very limited keyboard in the application. Every time you press any key the list of matching movies is fetched again. When the list of movies is being fetched the keyboard no longer responds properly. If I have filtered the results by clicking on the “Watch Now” tab then it flicks back to all movies before showing me the results. On most sites with an auto-complete field on the web there is a delay of half a second or so before the search begins. This helps to prevent extraneous searches, and improve the experience for the user. A delay of a second or so without the focus moving or a button being pressed on the keyboard before a search is sent would help greatly. I could type in a more specific search and find what I’m looking for much more quickly. If I’ve previously chosen the “Watch Now” tab then this should be the default tab that I’m shown when the results are returned.

I can understand that the keyboard isn’t the default system keyboard for the PS3 because LOVEFiLM’s keyboard allows a narrowing down of results in something like real-time, whereas the PS3 keyboard takes over the whole screen and only fills in the text field after you’ve finished typing. So perhaps there’s some work that could be done by Sony there to have a keyboard as a popup when in a text field or something. Perhaps LOVEFiLM could allow me to use the system keyboard if I want to. It would certainly make the search section easier to use for now.

Default PS3 controls are replaced
I use my Playstation to play a lot of media. Whether I am watching a DVD, Blu Ray, or downloaded video I know I can fast forward by holding down R2, rewind using L2, and pause by pressing Start, which is pretty much universal in the console world. In the LOVEFiLM application fast forward is the right-direction on the d-pad, rewind is left, and pause is the X button. This was quite confusing at first and I always pressed the wrong button the first time. Why is there a disagreement? Don’t Sony have guidelines similar to Apple/Google when it comes to apps for their systems? Things should behave in a similar way across a platform. To do otherwise just adds problems for the user.

No personal recommendations
When it comes to picking movies to watch you’ve either got to know what you want and search for it, or find it in the Most Popular section, the Highest Rated Section, or the collections. LOVEFiLM have a bunch of ratings from films I’ve rented from them. They suggest films that I might like to watch when I visit their website. Why not pass that information over to the PS3 application? In fact, why not just return a section called “Films on your Rental List” that are available to Watch Now? The information is available with a simple call to their API.

I’m sure the whole thing will get better with updated versions of the software, and it is usable for now, but it could be so much better.

Theremin-eqsue HTML5

I’ve spent the last few days thinking about theremins, the musical instrument that you play without touching. When I went to see a band called Spaceships Are Cool the other day it triggered my mind. One night I suddenly decided it would be possible to make a theremin that worked using only one hand using a different design.

I plan to make one at some point in the future, when I get the parts in one place… For now I decided that I would build my concept in the browser. I started out making it with a bunch of div tags, which was frustrating, and then I realised that I could use the <canvas> tag from HTML5 to do it.

I threw together a quick page and then began thinking about the sound. I found a page detailing generating sound in Javascript in Firefox 4 and decided to go with that. I installed Firefox 4 and then started playing around with scripting everything. I started out by picking apart Paul Irish’s harmony.js file (view that site in Google Chrome and scroll to the bottom). Then I added in the sound stuff once I had values for the cursor position.

What I ended up with was a very plain page that generates sound (in Firefox 4) with the pitch determined by the cursor position on the X axis, and the volume on the Y axis. The sample time is 50ms, and at the moment there’s a bit of an annoying click. I think I might be able to get rid of that by keeping the audio element playing at 0 volume or something like that, but that’s debugging for another day.

Anyway, if you’re viewing this on my page in Firefox 4 then you should see the finished product underneath. If you’re viewing this in a feed or on Facebook then you’ll want to go here. If you’re not using Firefox 4, or you’re not sure what browser you’re using then this probably won’t work for you and you’re probably very bored of reading this by now.

Facebook share button shows no count

Share

I was working on adding a Facebook Share button to blog posts at work and I couldn't seem to get it to display the speech bubble with the number of shares without clicking on the icon.

I did a whole bunch of searching and it turned out that it was caused by some Javascript from Facebook that only displays the count if it's more than 3. I don't really like the inconsistency of that, so I looked for a way to get it displayed even if it's zero. A guy named Patrick Kelly suggests getting your own local copy of the Facebook Javascript (FB.Share) and modifying the displayBox() function call so it shows any number. This is fine for now in that it will work, but as Patrick points out on his blog, it will potentially break if Facebook update their API, or make other changes to the underlying code.

I decided to pick apart the code and come up with a solution that doesn't involve the same issues. The fix is fairly basic. You just need to include the share button in the same way as Facebook tells you, and then insert the following Javascript after that:

<script type="text/javascript">
var buttons = document.getElementsByName('fb_share');
var count = buttons.length;
for(var i = 0; i<count; i++) {
  var data = FB.Share.getUrl(buttons[i]);
  if(FB.Share.results[data]) {
    buttons[i].fb_count = FB.Share.results[data].total_count;
  }
  FB.Share.displayBox(buttons[i], 0);
}
</script>

Hopefully that's a bit tidier than copying and editing the FB.Share file. It also means that you'll benefit from a cached version of the code being presented to the user if they've been on any other site with that button. A fairly tiny benefit, but every little helps. ๐Ÿ™‚

Programming cats

Have you ever wondered how many cats you would have if you started with just one female and left it alone with males for 5 years?

No? Nor had I… Until this morning!

I connected to the IdleMonkeys IRC server and was greeted by the following statement from Zach:

Did you know that 1 female cat not spayed will produce in 5 years, through her offspring and their offspring and their offspring etc. etc. 700,000!

I thought this sounded high, and so Zach and I did a few pointless calculations before I got the idea to write a script that would simulate this whole thing. I started out by writing a module to represent a cat. I called it Cat.pm and it looks like this:

package Cat;
use strict;
use base qw(Class::Accessor::Fast);
Cat->mk_accessors(qw(gender age pregnant pregnant_days gestation_period days_since_litter sexual_maturity));

1;

Very simply it defines a few values like the age and gender of a cat. Thanks to Class:Accessor::Fast I can easily get and set these values in my main script using something like this:

my $cat = Cat->new({ gender => 'Male', age => 0''});

Or

$cat->gender('Female');
$cat->age(12); #Age in days

I did a bunch of “research” (thanks Wikipedia) on the reproductive habits of the common house cat and found the ranges to configure for the gestation period, age of sexual maturity, etc. etc. It turns out that a female cat can be sexually mature at 5 months old, and can give birth around 2 months later. Cats tend to mate for 9 months of the year, skipping winter. After giving birth to around 3-5 kittens most cats have a period of at least around a month where they don’t get pregnant again, although it could be a lot longer. Zach asked me to specify that 60% of the cats born in a litter be female. I have no figures to suggest this is accurate, but I went with it anyway.

I programmed the first version of my script before I knew all of those facts and arrived at a number of around 5 million cats after 5 years of breeding. This was obviously ridiculous, and so I revised my script a few times.

With all the information I gathered I came up with a much lower figure than either of the previous ones. Over 10 runs of the script the average number of cats after 5 years was 16492.4. I ran the script through 1000 complete iterations and generated an average for all runs. The script took 3 hours 38 minutes and 15 seconds to execute and calculated an average of 10400.693 cats. ๐Ÿ™‚

There are a few problems with this script:

  • The first major problem is that there is no notion of males breeding with any females that are not descendants of the first cat. If other non-related females were around then the number would be significantly higher, as the males would be able to mate with all of them, and would produce a huge increase in numbers. So, this whole thing assumes that there is only one female cat in the entire world when the script starts running.
  • The script assumes that the first cat is born right at the beginning of the breeding season. If that changes then the figures would probably be quite different.
  • The script assumes that a cat will become pregnant exactly 30 days after giving birth to the previous litter (assuming it is within the breeding season).

Obviously there are many other shortcomings, but there will always be some when simulating any sort of behaviour like this.

Browser frustrations

Earlier on I was writing some code that inserted some text into a textarea on a webpage. After the text has been inserted I needed the cursor to be at the end of the textarea so that the user could then type more text in afterwards without any messing around.

I thought it would be a simple matter, but it turned out to be quite frustrating.

Needed for all
var t = document.getElementById('add-comment');

Gecko (Firefox, Mozilla, etc.)
t.focus();

Webkit (Chrome, Safari, etc.)
t.selectionStart(t.value.length);
t.selectionEnd(t.value.length);

Internet Explorer
t.setSelectionRange(t.value.length, t.value.length);
t.focus();

Is there some standard way of doing this that I’m unaware of? I think jQuery would be overkill for this one purpose.

Cash Gordon sucks

Just been looking at the Cash Gordon website and decided it’s not very good. Thought I’d share that with you all. ๐Ÿ™‚

More info
I just thought I’d take a second to explain this post… The Conservative Party put up a website that I’m not going to bother linking to that had a Twitter stream of all posts with a certain hashtag. They had no filtering of content, and no sanitising either. All HTML and Javascript got rendered directly on their page.

Cue carnage. People posted massive pictures, huge text, and a few people (myself included) posted Javascript redicrects to various other sites around the Internet.

The site appears to be down now. Whether that’s on purpose by the sysadmin team in the data centre, or because of a DDoS I don’t know. I guess it won’t be coming back up in its original form though. ๐Ÿ™‚

Google Analytics data:
Cash Gordon Google Analytics data

It was fun while it lasted.