Enough Packaging?

24 September 2007

After some trouble with our Belkin router recently, we managed to get it replaced under the lifetime warranty — a very satisfying result! The router arrived today, and the packaging that brought it can only be described as overkill:

Is this a Russian router?

I’m all for my package arriving in good condition, and this extra padding certainly facilitates that, but was all that necessary? Oh well, it works!

Ooh, Vector Art

10 May 2007

Today I stumbled upon this vectorising tool, called textorizer, that converts images into SVG format. You can specify your own text and size, as well as playing around with the edge-finding sensitivity.

Here’s the result on the logo used on my RSS feeds:

Vectorised version of RSS logo, using the text “buxâ€Â, 1000 strokes, 100 threshold, and 800×600.

Obviously it works less well for full-depth images, but messing around with the threshold helps. Have fun!


MySQL Joys

8 May 2007

1NF teaches us that we should not store repeating groups in fields. Given that we have a table satisfying 1NF containing values as such:

person_id transaction_id
11
21
12
13

It is simple to select all people involved in a transaction, or all transactions attributed to one person. But how would we find out, say, those people who had been involved in both transaction 1 and transaction 2? It wasn’t clear to me, until now:

SELECT `person_id`
  FROM (
    SELECT `person_id`
      FROM `table`
      WHERE `transaction_id` IN (1, 2)
  )
  AS `people`
  GROUP BY `person_id`
  HAVING COUNT(`person_id`) = 2

The first SELECT returns all those people that have been in either of the two transactions. The second groups the people, and selects those that appear twice — in other words, those that were in both transactions. It looks so simple in hindsight!

This has interesting extensions — one could select people that have appeared in any number of an arbitrary list of transactions.

It is possible to avoid a second SELECT by using GROUP_CONCAT(), but that loses some of the functionality — as well as the elegance.

My Favourite Number

3 May 2007 | 3 comments

I love the Internet. I love how countless code monkey hours are wasted trying to stop the inevitable. I love how people actually think it’s possible to remove information from the Word Wide Web.

So back to my favourite number. Well, it’s not prime, and it’s not perfect, so it’s not really my favourite number, and in fact the prime factors aren’t really that interesting: 26 · 5 · 19 · 12043 · 216493 · 836256503069278983442067. It did make it onto Wikipedia, however, and it did crash Digg for a full ten minutes. The reason? It’s a lot more interesting when represented in hexadecimal:

09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0

Just thought I’d let you know.

Gmail in Multiple Clients

30 April 2007

Gmail has always confused me that when opening POP emails from multiple clients, only those opened in that client show up. In other words, if you open up an email using client A, you can’t open it in client B — you have to view it in webmail.

Of course, there’s a workaround, provided in the help centre. The solution is to use your login as “recent:username@gmail.com”, rather than the usual “username@gmail.com”. This is apparently automatic on mobile devices, but I don’t see why it’s not the default…

Blog Accepts Media Network Commenting

20 April 2007

This blog now allows you to comment using your Media Network profile — just select “Media Network” as the login method and enter your user name and password. Your account must be activated to make a comment.

If your Media Network profile is associated with a tag profile, then your tag avatar and name will be shown, otherwise your forum avatar and user name will be displayed with the comment.

Internal Anchors

1 April 2007

Well, it was an interesting hour that resulted in this…

Facebook notes employ a redirect script for any links found in the note. There is a problem, however, when the link in question contains an apostrophe. The apostrophe is then matched out to its numerical code '.

This was relevant to me since the pictures site has certain URLs containing apostrophes, and the Facebook links were displaying the error page.

Before this error page is shown, I check a number of options to see if the link might be corrected, so I wanted to add a correction for this case. So I thought a simple string replace of “'” with “'” would work. Nope.

I soon realised that this was because the URL contained a hash, meaning it was pointing to an internal anchor (for example, /path/to/page-with'apostrophe actually went to /path/to/page-with& and tried to find an anchor called 039;apostrophe. So I needed to get the name of the anchor requested as well.

Not possible with PHP. After seeing the explanation in one forum topic, and seeing it clarified in another, I find that the anchor request never actually leaves the browser — it makes the page request, then searches in the result for the anchor. This means that no server-side scripting is going to work.

JavaScript it is, then. Here’s the workaround:

if (!isNaN(parseInt(window.location.hash.substring(1, 2)))) {
    window.location = window.location.href.replace(/&#(d+);/g, function(w, p) { 
        return String.fromCharCode(+p);
    });
}

This only replaces the one problematic example, but the condition now matches any case, thanks to TheScripts: since the anchor is CDATA (either through name or id), it must begin with a letter, so only incorrect anchors are checked.

PHP Snippets

23 March 2007

Whilst browsing the old Invisible Shadow network, I was looking to see if any of the old stuff existed on there. One thing I remember was a section for code snippets, both Visual Basic and PHP. It seems that Logan has started it up again. I always recommend that the best way to learn to program is to read others’ code — this kind of website helps with that.

It’s a bit sparse at the moment, having just restarted, but once established these sites can become a useful resource for any level of programmer. Good work Logan!

OpenID Now Working

17 February 2007 | 2 comments

After my attempts earlier this week, I have managed to get OpenID working on the blog. I haven’t yet sorted out any linking of an OpenID with either a Media Network profile or a tag profile, but it’ll be added in soon.

Fortunately, it actually only required minor modification of the bBlog class. I decided to post the comment prior to authentication, simply awaiting moderation. Then the comment ID is passed as part of the return URL, along with an auth code to make sure that no-one can steal another user’s comments by modifying the authentication URL. I really need to check what happens in the event of a failure or a cancel, but otherwise it’s all good!

Adapting for OpenID

14 February 2007 | 1 comment

Adapting for OpenID is no fun. Especially when:

  1. bBlog is particularly difficult to extend in this area, even though being Smarty-based it’s supposed to be highly customisable;
  2. there is so little comprehensive documentation for being an OpenID consumer.
Being an IdP is simple; the OpenID consumer sends a request to the IdP (in this case, http://cmbuckley.co.uk/myid/) and, if successful, the user is redirected back to the consumer to confirm that the user has logged in successfully.

Doing this the other way round, with the blog as the consumer, the bBlog class gives a bit of a problem: The commenting method is written quite strongly for the POST method — which I’d like to keep, as I don’t really like submitting forms with GET anyway. However, the set-up for OpenID is very GET-orientated, so I’d have to almost completely rewrite the function for adding a new comment. And then I have to decide whether I send the comment to the IdP as part of the successful URL, or hold it in some sort of session variable or other method. Either way, if the comment is submitted at the same time as the OpenID, then the comment has to wait.

Add to this the fact that hardly anyone really supports, uses or even knows about OpenID, and you might wonder why I’m even thinking about this yet. I’ll probably have to change everything for the 2.0 specification anyway…