• 08 Sep 2007 /  Uncategorized

    The problem: Windows doesn’t have an inbuilt SSH client, so trying to check out files from a Subversion repository over SSH doesn’t work out of the box. I’ve just spend half an hour looking for a way round this, and here it is [as ever, you follow my advice at your own risk]:

    1. I couldn’t manage to get it working using PuTTY. Please leave a comment if you have.
    2. Install Cygwin, making sure to include the openssh package
    3. Edit the C:\Documents and Settings\(yourusername)\Application Data\Subversion\config file to include a line reading
      ssh = c:/(cygwin root path)/bin/ssh.exe -i "C:/privatekeypath"
    4. You can omit the -i option and the bit after it if you don’t have SSH key authentication set up. If you’re using it, though, make sure you use forward slashes in the path to the key file. Note that the private key needs to be in OpenSSH compatible format. If you have key authentication set up in PuTTY, you can export your private key to an OpenSSH compatible version using PuTTYgen.
    5. You should now be able to check out repositories in the usual way from a command prompt:
      svn co svn+ssh://you@repositoryhost/path/to/repository/ destination-dir

      If you exported your PuTTY key as described above, you shouldn’t be prompted for your password on hosts where the corresponding public key is in place.

    Update

    Since writing this post, I’ve had Tortoise SVN recommended to me

  • 28 Jul 2007 /  Code

    Recently, I’ve been working on a new project, an update to the Magdalen College JCR Rooms Database. Doing this whilst on holiday with no internet connection certainly made me appreciate the reference panel built into Dreamweaver. However, it didn’t help me with the following problem: to simplify slightly, suppose you have a database table like so:

    +----+---------+---------+
    | id | version | name    |
    +----+---------+---------+
    |  0 |       1 | apple   |
    |  0 |       2 | apple2  |
    |  1 |       1 | orange  |
    |  1 |       2 | orange2 |
    +----+---------+---------+

    Let’s call it fruit. The primary key is the composition of the id and version fields, each group of rows with the same id being different versions of the same object’s details. Possibly not the best idea in the world, in retrospect, but it was too late now.

    What I wanted to do was get the row with maximum revision within each id, i.e. a single SQL query which would return

    +----+---------+
    | id | name    |
    +----+---------+
    |  0 | apple2  |
    |  1 | orange2 |
    +----+---------+

    Getting the maximum version number within each id is, of course, as simple as

    SELECT id, MAX(revision) from fruit GROUP BY id

    .
    Then you could do a second query like

    SELECT * FROM fruit WHERE id = '$id' AND version='$ver'

    to get the rest of each row, plugging in the maximum version from the first query and working through the rows one at a time…which is fine, except that there are 250 of them in the real thing, and that’s only going to increase.

    Methods involving multiple separate queries were out. Quite apart from the performance issues, I wanted a single query to allow me to search through the latest revisions of all rows by adding to the WHERE clause.

    After much further head-scratching, I came up with

    SELECT * FROM fruit GROUP BY id HAVING version=MAX(version)

    …which returned precisely the square root of stuff all. Initial investigations when back at an internet connection led me to blame this on the rather ancient version of MySQL doing service as development SQL server on my laptop; however, upgrading to the latest stable version didn’t help.

    What did help, though - and at last we reach the point of this rather large post - were these pages, which pointed me in the direction of this one, and told me everything I ever wanted to know about the “groupwise maximum” problem, as I discovered it was called. The solution I’ll be using, paraphrased from the examples on that last page, is

    SELECT fruit1.id, fruit1.name from fruit AS fruit1,
    (SELECT id, MAX(version) AS ver FROM fruit GROUP BY id) AS fruit2
    WHERE fruit1.id=fruit2.id
    AND fruit1.version = fruit2.ver;
    

    The bracketed expression is a sub-query, which internally creates a temporary table to match the maximum versions from. Searching through the results is just a case of adding AND fruit1.field = ‘value’ to the outer WHERE clause.

    All of which is quite enough SQL for one day, and leaves me realising I still have much to learn about it.

  • 27 Jun 2007 /  Web Design

    So, I’ve spent the last 48 hours writing a couple of style sheets.

    The first one, as the regular readers amongst you will notice, was for this site (apologies to those of you reading this on Planet CompSoc, you’ll have to click through to see what I’m on about). I’ve gone for a minimalist black-and-white look. I’m not entirely happy with it, but I’ll keep tweaking…

    The second, still very much in progress, is for the Magdalen College JCR site, which I’m giving a comprehensive makeover this summer. Feel free to leave a comment on either - constructive criticism is always welcome.

    Update

    Apologies to anyone who visited this site at about 20.40 BST on 27/06/2007 and wondered what the heck had happened to the new theme this post mentioned. Suffice to say that the correct way to fiddle with WordPress is to start in the backend manager, not to do random find-and-replaces across the underlying code. Don’t try and rename the directory the current theme lives in, either.

  • 20 May 2007 /  Web Design

    So, after a few weeks of holding pages and messing around, my site is now up, and it’s here to stay. The default WordPress theme certainly isn’t; chances are I won’t have time to make a nice new one until the end of June, though. As some of you may have seen, I had a go, but it ended up being not much better than my first ever attempt at web design, so clearly I need to take the time to do it properly. Watch this space…

  • 20 May 2007 /  Code, Facebook

    Every Friday, I get emailed a big spreadsheet of dinner menus for the next week. And every Friday, I spend 25 minutes copying, pasting and typing out times to get these menus into daily events for ‘Lunch’ and ‘Dinner’ on a website powered by the Mambo CMS.

    Actually, of course, I got bored of that after the first two weeks and lashed together a PHP form to cut out most of the effort; that reduced the task to about 5 minutes’ worth. But that’s still 5 minutes of my life I’ll loose each week…until now.

    Enter Python, specifically python-excelerator and xls2list. Amazingly, it turns out some clever people have already done the hard work of getting Python to read .xls files, so all I had to do was write a parser to fish out the menus.

    After some fiddling around, it seems to do the job on test data from the last few weeks. So now all I need to do is wire it up to a special email address at one end and make it output the menus into the Mambo backend database at the other.

Bad Behavior has blocked 34 access attempts in the last 7 days.