Categories
Apple

Apple keyboard symbols

There’s been a lot of comment about Apple removing the Apple symbol from the command key on the new iMac keyboard, and adding the word ‘command’. I tend to agree that it’s a good thing. It saves on those ever-popular Just hit command-S. No, the one with the cloverleaf on it. conversations, and it was never supposed to be called the Apple key anyway, as far as I know.

What puzzles me is why they seem to have removed the symbol from the option key (which I refuse to call ‘alt’) on all their recent keyboards. What are new Mac users going to think when they are presented with a shortcut description on a menu that looks like cmd-option-S, and there’s no key with the Option symbol?

Categories
General nonsense Rants

Free papers

T-shirtHow do Londoners put up with the hordes of people that try to force a free paper into your hands every ten yards? It drives me mad every time I’m down there.

I think I might have to get a T-shirt made.

Categories
Web 2.0

Wired on opening FaceBook

It seems like I’m far from being the only one who doesn’t like the walled garden nature of FaceBook. There’s now an article on Wired bemoaning the same thing.

Interestingly, they come to the same conclusion that I’d been meaning to blog about for a while: that we need massive adoption of XFN to start pulling all the various social networks together.

Categories
General nonsense

Super-thin wallet

My All-Ett arrived today, and they weren’t joking about the (lack of) thickness! With the same contents, the new one is about a third of the thickness (less than 0.4 inches, compared to 1.1).

Here’s my old wallet:

Old wallet

And here’s the All-Ett, with exactly the same contents (13 cards, a couple of books of stamps, and some cash):

All-Ett

The picture below shows the empty old wallet next to the full All-Ett.

Empty Animal wallet next to full All-Ett

It only cost just over a tenner too, including postage from the US.

Categories
General nonsense

Big Visible Belly

Firstly, acknowledgment to Brian Marick, from whom this idea is blatantly stolen.

In an attempt to shame myself into losing a bit of weight, I’m adopting the XP Big Visible Chart approach, with the ‘Big Visible Belly’ graph that now appears at the top of my blog.

The graph is generated by a simple Rails app (here’s the source), using the Sparklines library. The red area above the line represents weights above the top of my ideal weight range, and the green areas below the line indicate a healthy weight. The scales are one pixel per week on the x-axis, and one per pound on the y-axis.

[UPDATE] After posting the initial version I realised that something was wrong, as there ought to have been a tiny bit of green on the graph, and it was all red. After playing with the sparklines library for a while I decided that either it had a bug or I was completely misunderstanding something. I’ve now given up on it, and implemented the graph using raw RMagick calls.

Categories
Ruby

Unimplemented specs in RSpec

One of RSpec‘s many neat features is the ability to insert placeholder specs. These allow you to list a whole bunch of expected behaviour up front, without having to implement either the specs or the code, and without creating a huge swath of failing specs. All you need to do is omit the body of the specify or it block. Here’s a trivial example:

describe "The string 'foo'" do
  before do
    @foo = 'foo'
  end
  
  it "should be three characters long" do
    @foo.size.should == 3
  end
  
  it "should be capitalised to 'Foo'"
end
$ spec -f s foo_spec.rb                     

The string 'foo'
- should be three characters long
- should be capitalised to 'Foo' (NOT IMPLEMENTED)

Finished in 0.011201 seconds

2 examples, 0 failures, 1 not implemented

[tags]ruby,rspec[/tags]

Categories
Web 2.0

Facebook

I signed up to FaceBook a few weeks ago to see what all the fuss was about, and I’m still not sure I really understand.

OK, so it’s yet another social networking site, and it’s probably better than most of the rest. You can use it to store your photos (like Flickr) or videos (like YouTube), or to post regular status updates (like Twitter) And it’s got lots of ‘fun’ little applications, if you’re into that kind of thing. It’s got an API too, so it seems to have gained something of a reputation for being an open platform.

But how open is it?

I can show my Flickr photos on FaceBook, but as far as I can tell if I posted my photos directly onto FaceBook I couldn’t share them with the world at large. I can show my Twitter status on FaceBook, but I can’t just make it use that for my FaceBook status (or at least not without a lot of work). I could use the site like a blog, but then only a tiny invited audience would get to see my ramblings (big loss, I know). The whole site needs login, so it’s not externally searchable.

All the FaceBook applications seem to either exist solely within the site itself, or to just be a window onto somewhere else. There’s no real interaction going on. There are no APIs to allow other applications to access FaceBook data – it’s all one-way traffic. There aren’t even any RSS feeds.

It seems like FaceBook are making a play to become the Microsoft Windows of the social networking world – the common interface to everyone’s applications. Maybe it’s because I’m a long-time Mac user, but that makes me really nervous.

Categories
Ruby Web 2.0

Updating FaceBook status from Twitter

I’ve recently jumped on the Facebook bandwagon. I can’t be bothered to update two statuses (I rarely get round to it with one), so I was looking for a way to update my FaceBook status from Twitter. I installed the Twitter application in FaceBook, but that just displays the Twitter status separately.

It seemed that the only way to do it was to write a script to regularly check Twitter, and update FaceBook when it found a new Twitter message. I found a partial solution in PHP, but decided to roll my own in Ruby anyway.

It took a few hours longer than I expected (the documentation for Net::HTTP could be better), but I got there in the end. I now have the script below installed on my DreamHost account, and set to fire every minute via cron. It’s not the prettiest code I’ve ever written, but it does the job. Feel free to borrow it if you think it’ll be useful.

Andrew ‘Boz’ Bosworth
11:29pm September 6th

I’m an engineer at facebook and I’m writing to ask if you would be willing to take down the link to your facebook/twitter status sync utility (located on your website kerrybuckley.com). Based on your comment on TechCrunch I suspect you anticipated this would be coming at some point. Even if your intended use of such a script is noble (as I’m sure it is), the simple script you have posted on your site is (and has always been) against our terms of service. Said more shortly, we just can’t let people automate aginst our site outside of the platform; it’s a slippery slope.

We’d obviously like to resolve this without disabling your account or getting the lawyers involved if possible, so please let me know as soon as you’ve taken the script down so that our legal department doesn’t get all fired up about this.

thanks,
Andrew Bosworth
Facebook Engineer

My reply:

Andrew,

As you’ll probably expect, I’m not particularly impressed with Facebook’s current stance on openness in general, or on this issue in particular. I hope that at some point you add an API to allow remote updating of status, in the same way that you recently added an RSS feed to allow tracking of friends’ statuses.

For the record, I don’t believe that posting the script on an external site constitutes a violation of the terms of service, although I accept that using it would be. Also, when you say “we can’t just let people automate”, I assume you really mean “we won’t just let people automate”. This is a shame, as it goes against the grain of the Internet, and reinforces the impression that you’re trying to lock people into your site.

All that said, I don’t particularly want to be spending my time fending off writs and takedown notices, so the script no longer appears on my site (see http://www.kerrybuckley.com/2007/07/14/updating-facebook-status-from-twitter/).

Kerry

[tags]facebook, twitter, ruby, mashup[/tags]

Categories
Web 2.0

Cool “Web 2.0” introductory videos from the Common Craft Show

There are some great short videos on commoncraft.com explaining some Web 2.0 concepts for non-technical people. The lo-fi style is very clever, too.

So far they’ve done RSS, wikis and social networking (see below).

Categories
Rails

Correct use of the flash in Rails

[Update 9 May 2012]

This seems to work for testing flash.now in Rails 3:

it "puts an error in the flash" do
  post :create
  flash[:error].should == "Sorry, that's wrong."
end

it "does not persist the flash" do
  post :create
  flash.sweep
  flash[:error].should be_nil
end

[Update 20 April 2010]

I recently had problems testing flash.now, and Google kept leading me back to this post. Unfortunately it doesn’t seem to work with the current version of Rails (I’m using 2.3.5 at the moment).

This post from Pluit Solutions gives an alternative approach which seems to work. I haven’t tried it with Rails 3 though.


I don’t know whether this has caught anyone else out, or whether we just didn’t read the documentation properly (it’s covered briefly on p153 of AWDwR), but I thought I’d mention it anyway.

Anyone who’s written a Rails app will know that the ‘flash’ is used to store error and status messages, usually on form submissions. Model validation failure messages automatically get copied into the flash, but you often want to do it manually too.

flash[:notice] = "User Details updated."
redirect_to edit_user_path(@user)

The gotcha comes when you want to display a message and render a page, as opposed to redirecting – for example when errors are preventing a form from being submitted. This is how not to do it:

flash[:error] = "Password doesn't match confirmation." # WRONG!
render :action => 'change_password'

The problem is that the flash is stored for the next request. Because we’re no longer doing a redirect, that means the message may appear wherever the user goes next, not just on the page that we just rendered. To avoid this, use flash.now, which is only used for the current request:

flash.now[:error] = "Password doesn't match confirmation."
render :action => 'change_password'

The rule of thumb is to use flash if you’re redirecting, and flash.now if you’re rendering (either explicitly, or by dropping through to the default view for the action).

All very well, but whatever you put in flash.now is cleared out at the end of the request, so how do you test it? The answer (for RSpec, at least) lies in a comment on this RSpec feature request – basically just add the following to spec_helper.rb:

module ActionController
  module Flash
    class FlashHash 
      def initialize
        @hash = {}
        @now_hash = {}
      end
    
      def [](key)
        @hash[key]
      end
    
      def []=(key, obj)
        @hash[key] = obj
      end
    
      def discard(k = nil)
        initialize
      end
    
      def now
        @now_hash
      end
    
      def update(hash)
        @hash.update(hash)
      end
      
      def sweep
        # do nothing
      end
    end
  end
end

You can now do something like this:

describe "When a user tries to change his password with an invalid verification code" do
  ...

  it "should put an error message in the flash" do
    flash.now[:error].should == "Incorrect verification code or password."
  end
  
  it "should not persist the flash" do
    flash[:error].should be_nil
  end
end

[tags]Ruby,Rails,flash,RSpec[/tags]