Wednesday 24th January, 2007
Vertical centring (centering for the U.S people) in CSS: One trick that has proved quite tricky in CSS is to put an element in the centre of the window (or any other element) both vertically and horizontally. It is, however, possible to do this by means of a cunning arrangement of strut elements and judicious application of inline block elements (which behave like images do; a block element that flows as an item within the text). An example of this can be found at /examples/centring.html. This has been tested on recent versions of Firefox, Safari and Internet Explorer, but should not be treated as necessarily accurate. Accusations can be levelled at it of not correctly using CSS, but as there seems to be no way of using CSS that is all of sane, correct and working, this argument lacks a certain punch.

The vertical-align CSS property is used to align elements on a line, rather than relative to their container (as valign="center" did). However, a "strut" the full height of the parent element can be used; subsequent elements with vertical-align: center will be aligned with their centres on a line with the centre of the strut element, and thus with the centre of the containing element. Note there are some caveats; the containing element must have a definite height (even if it is a percentage), for example, but this is not usually a problem in situations where it is useful.

However, things are not quite this simple. Firstly, Firefox does not implement display: inline-block; it has a rough equivalent called -moz-inline-box, which doesn't work exactly the same as the w3 seem to think that it should, but is near enough for this purpose (those intending to make use of this technique are encouraged to beat their own heads off these differences). Also, Internet Explorer will not apply display: inline-block to elements that are already block elements, for whatever twisted reasons apply in these cases. Thus, you have to apply display: inline, display: inline-block and display: -moz-inline-box to any block that needs to behave as an inline-block. There is also a Firefox bug which seems to enforce that on certain versions no inline-block on a line can be any smaller than the first.

Thus, the solution consists of the following elements, all divs:

The CSS stylesheet for the example given in the first paragraph (containing border styling for educational use; these would be removed in most 'live' use) is:

.container {
        text-align: center;
        border: 1px solid green;
        height: 100%;
}

.ffhack {
        display: inline;
}

.ffhack {
        display: inline-block;
        display: -moz-inline-box;
        height: 0px;
        width: 0px;
        border: 1px solid black;
        vertical-align: middle;
}

.brace {
        display: inline;
}

.brace {
        display: inline-block;
        display: -moz-inline-box;
        height: 100%;
        width: 0px;
        border: 1px solid red;
        vertical-align: middle;
}

.cbox {
        display: inline;
}

.cbox {
        display: inline-block;
        display: -moz-inline-box;

        border: 1px solid blue;
        vertical-align: middle;
}

The container class contains the overall container; the brace class contains the strut; the ffhack class contains the 0x0 workaround for the Firefox bug mentioned earlier; the two rules for each class are necessary to work around the IE misfeature.

Also, it is snowing.

posted by Rob Mitchelmore, 02:34 (anchor)
Friday 12th January, 2007
Resuscitating Roland, or, how I learned to stop worrying and love fsdb(8): just before christmas, the server roland.midworld.co.uk suffered a sudden disc failure and fell over. This annoyed quite a lot of people as, due to various miscommunications and crises, the backup system was not as good as it might have been. After the failure, the machine would not successfully boot due to an error occurring in the superblock, although the disc itself showed up on the IDE bus.

First of all, the disc in the server was replaced, a newer version of OpenBSD was installed on it, and an image was taken of the old disc with dd(1) and backed up many many times. The image was then bound to a loopback device using vnconfig(8). There was an error over the disklabel, which ate the filesystem type for /dev/vnd0a, so this was fixed using disklabel(8) with the -E option. Then fsck(8) was run over the filesystem using -b 32 to specify an alternative superblock. This is rather where the fun began.

fsck immediately reported an overflow, wandered through the filesystem for a bit fixing and removing things and then promptly abnormally terminated with a segmentation fault. Rerunning it caused it to 'fix' more problems and then exit normally - its last action being to remove 'redundant' links to /, which had the effect of entirely removing every directory in /. This being a suboptimal result, a backup of the image was restored and another attempt was made.

Using the -b 32 and -y options to fsck and then hitting break has the useful side-effect of writing the backup superblock to the primary superblock and doing nothing else. Once this was done, the filesystem could be mounted read-only and some salvage work could be done. /home and /etc were sound and rescuable, but /var had disappeared completely - some of the time. It showed up in the normal ls listing, but not in ls -l.

Unmounting the partition and then running fsdb over the raw device showed the issue - the inode for the /var partition was broken and marked as unallocated. Each file, directory, device or special node in the filesystem has an associated inode; in UFS, all the file metadata and the addresses of the data zones associated with the file are kept in the inode while a directory is a set of (inode, name) pairs. This explains why /var did not show up in ls -l, as its metadata was missing, but did in ls, as its name (being attached to /) was intact. Any data underneath /var, for example the fairly crucial /var/www and /var/mysql directories, were thus marooned somewhere in limbo if they were intact at all.

fsdb has the ability to examine an inode by number; if that inode is a directory, it supports listing the contents with the 'ls' command. It also supports traversing the directory tree with 'cd'. If repairs need to be done then it will prompt as fsck does for y/n/F, where 'F' is 'fix all'. This can be used to write a simple program that interacts with fsdb to list every filename on a volume, albeit slowly and unpleasantly. The source code to a rudimentary utility to do this, ohfuck.c follows.

int main(int c, char** v) {
        int i;
        for (i=0;i<=4863488;i++) {
                printf("inode %d\nls\nF\n", i);
        }
}

This program was used on the input of fsdb to iterate through every inode on the partition, and then grep was used to find known directory names, for example:

./ohfuck | fsdb -f /dev/vnd0a 2>&1 | grep mysql

This gives a set of directory entries for 'mysql'. fsdb can then be used interactively to cd into each directory named 'mysql' and see if it is the correct one - in this case, it correctly found /var/mysql/mysql, and cd-ing to .. showed that the /var/mysql directory was intact. Once this had been found, a note was made of its inode number and this was substituted for the inode attached to /var in /. Thus the /var entry pointed to the directory that was /var/mysql - it could then be rescued with rsync -a to a backup directory. A similar procedure was followed to rescue /var/www.

The software we could remember installing was then reinstalled from ports, and all was well again with the world.

posted by Rob Mitchelmore, 01:14 (anchor)
Thursday 4th January, 2007
If, Sir, you were to put as much effort into maintaining your friendships as breaking them, then you would be twice the man you are now. That takes balls. You could stand tall.

It is possible to show this using Pythagoras. If your manliness is doubled and your height increases (assuming of course that your manliness is currently non-negative, as is suggested by the use of a gender-specific honorific) then your perceived masculinity, Mp will increase, your new Mp' being given by √(manliness2 + height2).

Furthermore assuming that due to biological constraints, increased self-respect cannot actually double your height, the gradient of your perceived masculinity (which is of course a vector quantity; the angle of the dangle and so forth) will be considerably lessened; leading to your being perceived as kinder, gentler, and yet more ballsy.

Thus it is beaten into the ground like a dead horse with a siege engine. QEF, QFT.

posted by Rob Mitchelmore, 14:24 (anchor)
June 2015May 2015April 2015June 2014
January 2014November 2013October 2013July 2013
April 2013March 2013January 2013November 2012
older posts