Time Machine & Ready NAS

February 20th, 2009

Thanks to the wonderful instructions here I now have Time Machine configured and it’s now backing up my user directory on an hourly basis.

See the video clip on Vimeo.

Python-by-example

April 2nd, 2008

Python-by-example is a great doco-n-example resource for Python’s standard library. Really handy stuff and something which should be done in the official docs.

Via: Simon Willison

S3 Browser for OS X

March 14th, 2008

Olivier Gutknecht’s S3 Browser appears to do all I need an S3 browser to do.

IE 8 - Developer Tools

March 5th, 2008

The Developer Tools for IE 8 look very like Firebug, which can only be considered a great thing.

Usability Issue for Mono Download Page

January 25th, 2008

I just read the Usability Disaster Story and was amazed by how many people didn’t click on the text link to the latest version. This just reinforces the need for user walkthroughs, as this would probably have been revealed in only a few minutes. I am going to do some videos of people using our products web site soon. It’s something I meant to do a long ago but time hasn’t permitted.

Python by xkcd

December 6th, 2007

Sum of the integers in a List

November 25th, 2007

I had to write some code recently which calculated the sum of the integers stored in a List. I went the longhand way about it and wrote something like:

i_list = [ 1, 2, 3, 4]

total = 0
for n in i_list:
  total += n

Of course the simplest way to do it is:

i_list = [ 1, 2, 3, 4]

total = sum(i_list)

So I wrote a very simple timing test to see if there was a significant performance hit:

def longhand(i_list):
    total = 0
    for i in i_list:
        total += i
    return total

def shorthand(i_list):
    return sum(i_list)

i_list = []
for i in range(0, 1000000):
    i_list.append(i)

import time

s = time.time()
x = shorthand(i_list)
#x = longhand(i_list)
f = time.time()

duration = f - s

print duration

I did ten runs using each method to sum the list of one million integers and the shorthand averaged 0.34 seconds while the longhand method averaged 0.51 seconds. If you are using small lists then the difference will be negligible but for very large lists you will benefit from using the sum builtin.

Windows ‘No Disk’ Error

November 20th, 2007

I recently came across a strange bug when I ran an installed version of some software on Windows. The following error dialog was being displayed:

No Disk

I have a network drive mapped on my machine so I unmapped it and then reran the process. No joy, the same error dialog was displayed.

I also have a one MemoryStick and one SD slot on my lappie, so I stuck a card into each one and reran. Everything worked fine. So I now knew it was directly linked to the removable media drives on the machine.

I did a bit of testing then and noted it that was a call to os.access which resulted in the error dialog.

I changed the code to use the win32api.GetFileAttributes call but this too resulted in the same ‘No Disk’ error.

I then tried to write a temp file to the root of the drive and if this failed deduce the drive was read only. This also produced the same ‘No Disk’ error.

I then had a thought, all these drives in windows are just logical drives. So there must be an api to find the physical drives that have been mounted. If I could get the list of physical drives I could probably find the logical drives that reside on them. I found the solution using WMI.

So here’s the snippet of code to find all writeable drives (fixed, removable and optical) on windows:

import win32con
SUPPORTED_DRIVES = [
  win32con.DRIVE_REMOVABLE,
  win32con.DRIVE_FIXED,
  win32con.DRIVE_CDROM
]

import wmi
w = wmi.WMI ()

drives = []
dd2dp = "Win32_DiskDriveToDiskPartition"
ld2p = "Win32_LogicalDiskToPartition"
for disk in w.Win32_DiskDrive():
  for partition in disk.associators(dd2p):
    for logical_disk in partition.associators(ld2p):
      drive = logical_disk.Caption
        if logical_disk.DriveType in SUPPORTED_DRIVES:
          if os.access(drive, os.W_OK):
            drives.append(drive)
          else:
            print "Ignoring read only drive '%s'" % drive
        else:
          print "Ignoring unsupported drive type '%s'" % drive

XRAY and MRI

November 1st, 2007

Roger Johansson brings two excellent bookmarklets to my attention.

XRAY lets you inspect the properties of any element on the page by opening a floating palette that displays the element type, id, class, position, size, border, margin, and padding of any element you click on. It also displays the element’s inheritance hierarchy.

MRI opens a similar floating window and has an input field where you can enter a CSS selector. When you click the MRI button, MRI highlights the elements on the page that are matched by the selector. MRI also works the other way around. Click anywhere on the page and it will suggest CSS selectors for the element you clicked on.

Very useful when you don’t have Firebug installed.

Update: Here are a couple of screenshots of it in action, first XRAY:

xray

and now MRI:

MRI

Ant Outline View in Eclipse

September 28th, 2007

The Ant outline view in Eclipse is not very useful:

ant_outline