Archive for April, 2008

HD webcam of Miraflores lock

Wednesday, April 30th, 2008

I found this HD webcam overlooking the Miraflores lock on the Panama canal. A fascinating reminder of the ever-turning wheels of trade, and great when you can see a panamax-class vessel go through (the largest that will fit, with less than a metre clearance on each side).

Updates are a little bit less regular than one would like, but it does work. I wonder how long it will be before we commonly see full-motion video of such sites?

Do you know what I see a lot of?

Monday, April 28th, 2008

Crash in a Flash

“May have”, indeed. “Was” would be more accurate. Even more accurate would be “was caused by the fucking Flash plug-in, AGAIN”.

I am beginning to wish Safari had a button to turn on flash only when you need it.

Flight404 processes Radiohead

Sunday, April 27th, 2008

I hate Radiohead but Flight404 makes it almost listenable with his amazing visualisation, done entirely in Processing. Although he did cheat and do the beat detection manually.

I recommend the 200MB quicktime version but there’s a smaller flash player on the blog post.

UPDATE: Seriously, this song is awful by any reasonable measure. If you think this song doesn’t suck, you’re delusional. “Weird fishes” indeed. Or is that WeIrD F1SH3S.

Build your own fully functional powered armed exoskeleton in one day, in a cave

Thursday, April 24th, 2008

I don’t mind suspending my disbelief for a good movie, and I’m sure Iron Man won’t disappoint. But come on – are the filmmakers seriously asking me to believe that a single man designed and built a fully functional, armed, armoured, self-supporting, powered exoskeletal suit – starting with nothing but some molten iron and a few wires – while locked in a cave – in under 24 hours?

I bet it took the props department a month, or more, to build even a non-functional wearer-supported unit out of plastic. I’m all for suspending disbelief in films, and I love exoskeletons, but come on.

Australia’s 2004 UNCLOS claim upheld

Tuesday, April 22nd, 2008

Good news for those following Australia’s 2004 submission to the UNCLOS Commission for extension of the recognised continental shelf of Australia – the claim has been upheld. Find the full submission , so you can see the new boundaries.

The new claim covers over 2.7 million sqkm, not including a placeholder claim staking out continental shelf around the Australian Antarctic Territory.

UNCLOS claim summary

Letter to Mackie

Wednesday, April 16th, 2008

Mackie, I love you but why are your prices in Australia so unbelievably high?

Check this out. I’d love to pick up a pair of your new MR5s for my home setup (I already have some HR824s, and they’re awesome). So I look at the prices.

USD $150 each at sweetwater
AUD $400 each at online stores here

A current currency conversion: 150 U.S. dollars = 163.51 Australian dollars.

Don’t bother pulling out your calculators, that’s a 245% increase AFTER currency conversion. Someone is making a killing here, and it’s your brand that looks like an absolute rip-off. And don’t say it’s shipping, they’re made in China and Australia is *closer*.

I know the Australian distribution is probably not really your #1 concern but please can someone at least take a look at it? These guys are making off like bandits. I don’t mind paying a little more since we’re a smallish market, but how could anyone pay that much more? Two and a half times as much is insane. If you wonder why you don’t have any customers here, now you know – your local distribution partners are ripping you off blind, and as for the customers – we all know how to find US prices, and we all know the AUD is practically equal to the USD.

Would *you* pay a 245% premium, no matter how much you like Mackie?

Well, anyway, thanks and I just wanted to get this off my chest. Great work on all the products as usual, I love them. Just please fix the pricing situation in Australia : (

thanks a lot!

Sho

UUIDs in Rails redux

Tuesday, April 15th, 2008

I have covered forcing ActiveRecord to respect UUID data types in Migrations before. That helps us create our database – now what about in use? We need to create the UUIDs and store them in the database.

These examples all rely on the uuidtools gem, so install that if you haven’t already (and require it somewhere in environment.rb).

1. Setting a UUID using ActiveRecord callbacks

If you don’t need the UUID in the object upon creation but only want to ensure it’s there upon save, do this. Suggestion initially from this page, changes are mine.

We will use the before_create callback to ask AR to add a UUID of our choosing before the record is saved.

Add this to your lib directory:

# lib/uuid_helper.rb
require 'uuidtools'
 
module UUIDHelper
  def before_create
    self.id = UUID.random_create.to_s
  end
end

And now include this in your models:

class Airframe < ActiveRecord::Base
  include UUIDHelper
 
  #my stuff
 
end
>> Airframe.new
=> #< Airframe id: nil, maker_id: nil>
>> Airframe.create!
=> #< Airframe id: "1a82a408-32e6-480e-941d-073a7e793299", maker_id: nil>

2. Initialising a model with a UUID

If you want the UUID in the model before save, i.e. upon initialisation, we have to get a little more fancy:

# lib/uuid_init.rb
require 'uuidtools'
 
module UUIDInit
  def initialize(attrs = {}, &block) 
   super 
   ['id'] = UUID.random_create.to_s
  end
end

Now include this in your models:

class Flightpath  < ActiveRecord::Base
 
  include UUIDInit
 
  # my stuff
 
end
>> Flightpath.new
=> #< Flightpath created_at: nil, id: "5e5bcd63-070d-4252-8556-2876ddd83b54">

Be aware that it will conflict with any other initialisation you do in there, so you might want to simply copy in the whole method if you need other fields upon initialisation:

class User < ActiveRecord::Base
 
  def initialize(attrs = {}, &block) 
   super 
   ['balance'] = 0.0
   ['id'] = UUID.random_create.to_s
  end
 
end
>> User.new
=> #

3. Sessions

All this is very well for your own models, but what about Rails’ inbuilt sessions? By default, they want an autoincrementing integer primary key.

The good news is it’s easy to override. Your migration should look like this:

create_table "sessions", :id => false, :force => true do |t|
  t.string   "session_id"
  t.text     "data"
  t.datetime "updated_at"
  t.datetime "created_at"
end

Now add this to your environment.rb file:

# config/environment.rb
CGI::Session::ActiveRecordStore::Session.primary_key = 'session_id'

And this to your Application Controller:

# app/controllers/application.rb
class ApplicationController < ActionController::Base
 
before_filter :config_session # at the top, if possible
 
def config_session
  session.model.id = session.session_id
end
 
end

And voila, your session store is using the session_id as its primary key. I don’t see any point in using a UUID for your sessions’ PK, but if you want to you’ll find an example override class in:

actionpack/lib/action_controller/session/active_record_store.rb.

Remember to drop any preexisting sessions table in your database, or it will likely complain of null ids when you switch to session_id as your primary key.

Dragon Ash: Palmas Rock

Sunday, April 13th, 2008

I can’t believe I’ve never posted any Dragon Ash to this blog. I’ll remedy that right now with my favourite song off their 2005 album Rio de Emocion, Palmas Rock.

Dragon Ash – Palmas Rock

Cloverfield

Friday, April 11th, 2008

I didn’t think I was going to like this movie, which is why I didn’t bother watching it until now. I don’t like LOST, which didn’t help my lack of enthusiasm. And I was wary after the film’s extremely effective viral marketing – experience has unfortunately shown that the better the marketing, the worse the film, more often than not.

Well, I was wrong – it was good – great, even. I understand why people don’t like it – but I think they miss the point. The goal of the movie isn’t to make yet another happy-happy good-guys-win and everybody lives happily ever after “Happy Independence Day Mr President” cookie cutter monster film with everything explained and wrapped up nicely for you, the goal is to make you feel like you’ve run around in NYC trying to avoid a fucking monster while all sorts of shit goes on. In that, it succeeds brilliantly. I tend to like “experience” films where the goal isn’t to tell you a story but instead to just make you feel something. In this, the film is very well done.

If you get motion sickness easily, if you need all the loose ends tied up and no questions remaining, if you need a big “plot” to validate your movie-going experience – don’t watch it, you’ll hate it. If, however, you’re willing to submit to the premise and just stop asking questions and take in the “evidence” then I think you’ll like it, I certainly did.

Bruce Sterling at Innovationsforum

Thursday, April 10th, 2008

I really enjoyed this talk by science fiction author Bruce Sterling at Innovationsforum Interaktionsdesign in Potsdam, Germany last year.

He’s one of the top 5 in my science fiction Leaderboard, even though I don’t actually like any of his books. Definitely interesting to hear his thoughts if you’re at all interested in the future of .. stuff. No word for it yet, really – “convergence” comes close. Sterling calls them SPIMEs but I don’t love that word.

Anyway check it out, if that’s your bag.

Import successful

Wednesday, April 9th, 2008

I’m happy to report that I’ve successfully imported all posts and comments from this blog into a new system. While I’m still unsure as to when that’s going to go live, I hope it’s soon – I’m sick of this blog. I mean just look at it! Ugly as hell. And so fucking common.

Anyway, looking forward to rm -rf’ing wordpress once and for all. Tally-ho!

Off topic but not really worthy of another post is a small annoyance I have with people talking about randomness in UUIDs. I often hear this quote bandied about as some sort of “proof” that UUID collisions will never occur:

1 trillion UUIDs would have to be created every nanosecond for 10 billion years to exhaust the number of UUIDs

This is a useless factoid which, while sounding superficially impressive, has no relevance to actual use of UUIDs. For starters – there’s no central authority tracking UUID use. Even in internal projects there’s usually nothing tracking their use. Most projects that I’m aware of have none, zero, zip duplicate protection or even detection. Not that this is a big problem, as this example a little further down the same Wikipedia page explains:

[..] after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%

Now admittedly that’s still a pretty unlikely event. Assuming you have a decent generator, you shouldn’t lose any sleep that your UUIDs are colliding .. or ever will in your lifetime. But 1 billion a second for 100 years is a lot less that 1 trillion a nanosecond for 10 billion years. Don’t just wave away about 15 orders of magnitude just to make a point.

Stop using TinyURL

Tuesday, April 8th, 2008

You know what I fucking hate?

Reading a web page, or an email, or anything at all where someone gives a link to a URL redirection service rather than the URL itself. Tinyurl.com is the most popular but there’s a number of them. Why the fuck do people do this?

If you don’t give the proper URL, I can’t tell:

  • Whether I’ve read it before
  • Whether it’s worth reading at all based on the source
  • Whether it’s a link to some likely spam/other hostile site
  • Whether I’m about to get “rickrolled” for the 15,000th time
  • Fucking anything at all

Why the hell do people do this? There’s plenty of room on the screen. If the intention is to fit on a small screen like a mobile, that should be done in the mobile software. If it’s HTML, use a freaking href.

There are some hideous URLs out there, I know. Just a few days ago I was talking with someone, looking at some real estate site, and pasting URLs back and forth – they were awful. About 10 lines of gibberish in Skype – literally hundreds of characters. But that is their fucking problem. Site operators should be forced to make decent URLs because if they’re that bad, people won’t use them. Using a URL redirection service simply removes the economic incentive for websites to clean up their act while adding needless obfuscation for the rest of us.

Adding to the idiocy is how some of the redirection sites have now added a “feature” which enables you to preview the URL before visiting. If that isn’t the most stupid thing I’ve ever heard, I don’t know what is. So, if I click this fake URL, I’ll be allowed to go to another website (with ads, of course) upon which I’m to be given the privilege of looking at the real URL, so I can decide whether to click it? This is insane! Just use the real URL in the first place!!

Everyone in the world, just stop doing this stupid shit already. Please.

DataMapper – one ORM to rule them all?

Tuesday, April 8th, 2008

I’ve just watched the DataMapper presentation from Mountain West 2008, and it’s very interesting. I’ve been thinking we need a high-level super-abstraction library for Ruby for some time, and DataMapper (DM) looks like it might grow into fitting that bill.

What’s wrong with what we’re using now? Let me count the ways – or rather, let me count how many different sources to and from which I am reading and writing data in a Rails app of mine today:

  1. An RDMBS (Postgres), using ActiveRecord
  2. A number of resources, using ActiveResource
  3. A document-based database, using a custom i/o library
  4. YAML config files, using a constant read from a file on server load
  5. Cookies, via ActionController
  6. (not really a full point) data structure information in Model files

That’s too many. And I see no sign of this trend slowing down – why, I just found out about the new project today, yet another library to address document-based databases. We have at least three gems to read and write to CouchDB. Thingfish uses Sequel. If you use Amazon S3 that’s yet another. Enough!

It’s more and more obvious that these new developments are being written at the wrong level of abstraction. I don’t know what we can do about Cookies but all the others – RDBMS, RESTful resources, YAML files, etc – are the same types of data and should be accessible by a common API within Rails or Merb or plain Ruby or anywhere. So why can’t we access them all via a common method?

The correct way to do this is to have a single ORM at the highest possible level of abstraction. Storage adapters can be added to it as drivers. Then, if you need to split storage types for whatever reason, you can configure that on a case by case basis.

DataMapper enables this, and provides a plug-in system – if you can implement 10 or so basic actions in your storage system, and support 5 or so basic data types, you should be able to use it transparently. To me, this is a very appealing step forward. There are many types of data storage, all with their strengths and weaknesses. If we can flexibly and transparently include pretty much any useful type of storage into our programs using a single consistent API and with just a little config, once, in one place, that’s a huge win.

Why not just improve ActiveRecord? I think it’s too late for that. AR is a huge, tangled mess which many believe should just be scrapped and re-written from scratch, me included. Well, the good news is that DM has basically done that, and it’s smaller, faster, more modular, cleaner and – best of all – mostly compatible.

UPDATE: Whilst looking at the weblog of Rails Core member Rick Olson, aka Technoweenie, for info on ActiveDocument I came across this wonderfully candid comment on AR associations:

I can point to a few other more complex areas of the associations code (the crazy eager joins code is why I personally haven’t used :include in any of my apps in over a year).

Straight from the horse’s mouth! Couldn’t agree more.

Inconsolata

Tuesday, April 8th, 2008

I have used Monaco for all my fixed-width text needs since I can remember. I do everything in Monaco – write emails, use terminal, TextMate, everything. I remember I used to use IRC in Monaco in fricking 1994. I love Monaco. “That awesome font on the Mac”, I used to think of it as.

But lately my eyes have been tiring while staring at TextMate all day so I’ve been tweaking a bit to try and reduce eyestrain. Changing syntax colouring, reducing contrast here, increasing it there – that kind of thing. Seems to work, a bit, I guess. But as part of that I also decided to check out what other fonts people thought were good and by that route I came across Inconsolata, perhaps the first monospace font I’ve ever thought was even comparable to wonderful, wonderful Monaco.

The problem is the serifs on Monaco. The lower-case “i”, for example, looks fantastic without its left bottom serif at 10 points. I maintain to this day that 10 pt Monaco is the single best way to represent text ever fucking invented, but at 14pt (the size I use it at in TextMate) the serifs that look so kewl at 10pt start to work against it a little.

Inconsolata is basically Monaco with a few tweaks that make a surprising amount of difference. I am not some kind of beret-wearing font expert, so I have no idea how to describe it, but at 14-16pt I find Inconsolata slightly easier to read than Monaco. My terminology is probably completely wrong, but it feels like Inconsolata is “hinted” slightly better – one doesn’t need to stare at a word quite so hard to discern its composition. The lower-case “i” is a good example – the serifs at the bottom, and slightly different spacing, make it more obviously a lower-case i at a glance. It’s subtle, but when you stare at something for 6+ hours per day even a subtle improvement becomes more than worthwhile.

Anyway, it’s a free & open source font and an easy install for OSX – download the OpenType file and just double click – so if fixed-width fonts are a big part of your day, I recommend giving it a shot and seeing what you think.

Rainbow Links

Saturday, April 5th, 2008

In an effort to give my blog more “bling”, I’ve enabled rainbow-coloured animated links.

Inspired by Do Your BEST!, whose QT4 tutorials I’ve been reading.

UPDATE: Found them infuriating and removed. Also reduced font size, which has gotten screwed up somehow.

Radiohead are greedy motherfuckers

Thursday, April 3rd, 2008

Wow, Radiohead have a remix competition! You can remix their song, “Nude”, and if you like it you might get a prize! Cool, huh – although I’m not really a fan, I’m all for artists promoting remixing of their own work. So maybe I’ll just grab the song parts, they’re sure to be free, right ..?

Oh no! They’re only available on the iTunes store. There’s 5 separate parts, sold as 5 different tracks. If you want to remix this song, you’ll have to buy all 5.

The greedy fucks. What’s wrong, Thom, not satisfied with the $10m you made from gouging fans for crappy low-bitrate mp3s? Now trying to charge through the nose to make a fan remix of your songs?

What a disgraceful, money-grubbing little shit Thom Yorke is. Want to remix this stupid song? Grab the audio from The Pirate Bay.

By the way, Radiohead sucks. Basically they’re whining British fags who just moan about their shitty lives all the time. I think. Actually, that’s just a guess – I have no idea what Radiohead sing about, I can’t stand them. All those people who say things like they’re the should all be shot.

I’m not saying all Radiohead fans are gay. Just, you know, be careful. Watch you back, if you know what I mean. That’s all.

Oh, and Trent Reznor did it first, did it better, and for free. Fuck you, Radiohead!

London Connections

Thursday, April 3rd, 2008

I’ve talked about Tokyo trains here quite a bit, so I thought it’s only fair to mention that other great train city of the world – London. Here’s a great blog which covers the world of rails (the other kind of rails) in ol’ Blighty.

And speaking of London, my airline-industry housemate has been telling hilarious stories about what an unmitigated cock-up the Terminal 5 opening at Heathrow has been. Planes forced to take off without any bags at all, mountains of tens of thousands of unsorted luggage sitting in no-mans-land (up to 40,000 at one point). A fleet of trucks driving thousands of suitcases to Milan ad elsewhere to be processed – screening them for air transport being all but impossible. The worldwide luggage forwarding system is a nightmarishly complex, labour-intensive system, and even a single lost item can create hours of work to return to its rightful owner, so a failure on the scale of Terminal 5 is a snowballing disaster which will keep BA staff working late for months. One can’t help but feel sorry for the poor chaps who will have to sort that out.

RESTful confusion

Tuesday, April 1st, 2008

REST confuses me. I’m trying to come up with a consistent, elegant RESTful interface to a web appplication, and I just can’t understand how I’m supposed to do it while maintaining “correct” RESTful design.

I see the advantages of using REST over, say, XML-RPC. I want to use it. But I’ve got serious questions and I can’t find any answers.

At the front of my list of questions is the biggest, most basic problem – that of credentials. How the hell do you send credentials as part of a REST request?

From wikipedia:

HTTP separates the notions of a web server and a web browser. This allows the implementation of each to vary from the other based on the client-server principle. When used RESTfully, HTTP is stateless. Each message contains all the information necessary to understand the request when combined with state at the resource. As a result, neither the client nor the server needs to remember any communication state between messages. Any state retained by the server must be modeled as a resource.

REST is supposed to be completely stateless. I understand that. That means no “sessions” or login keys or cookies for the client to remember and reuse. That also means the credentials must be sent with every request if I’m understanding it right.

So where are the credentials supposed to be? In the URL? Or in the form body (assuming a POST request)? If so, what about a GET request, which doesn’t have form body? And am I to assume that all REST requests requiring credentials are supposed to go over TLS? Why do none of the examples I see have any of this in them?

Since the whole point of using this is to standardise, are there standard form names (eg for username/password) we’re supposed to use? I have never seen what I consider to be a “canonical” example of this. In fact I have never seen a RESTful system using credentials of any kind which matches the first basic rule of what “is not REST” according to the RestWiki:

What is not REST?
- Stateful systems

Any system where you do not need to send the credentials more than once is stateful by definition.

Assume that we’re going to cheat a little and implement, say, a stateful session so we don’t have to log on every single time. Should the session token go in the URL? It has to, if it’s a GET and it usually will be. Or should we be faking out cookies? Again – if the session token is in the URL (a “secret” URL) that will need to be over TLS or anyone will be able to sniff it. But how else can you do sessions over HTTP GET without cookies? HTTP BASIC AUTH?

Confused yet? Me too. Has anyone ever actually implemented a pure RESTful system in an application that requires authentication?