Global challenge: Cambodia

13:29, Wednesday March 8th, 2006 • feeling enthusiastic • no comments

Project O revealed!

In November, Louise and I are going to ride 475km through Cambodia and Vietnam to raise money for Oxfam!

We've put up a website with all the info, you can even sponsor us online. We need to raise £5,200 between us, so we're grateful for any help you can give. We'll also be blogging (and moblogging) about our training and the event itself soon.

Aggregate operations in shell

17:25, Monday February 27th, 2006 • feeling relaxed • no comments

You might be familiar with aggregate clauses in SQL, you know, count(*) and friends. I was interested in performing aggregate functions on files of tab-separated data. I'd do an aggregate query in SQL, get a set of result rows, then I needed to total one column.

I output the data to TSV, using a mysql -e command and redirecting the output to a file. The data looks something like:

id      viewcount       comments
127067  341     44
127076  66      2
127077  158     6
127111  379     25
127112  83      3
127119  105     10
127131  47      0
127135  51      1
127137  133     17

I found that awk has the required mix of unix command line tool sensibilities and numeric functions. Here awk accumulates the 3rd value of each row and displays the total.

cat data.tsv | awk '{x+=$3} END {print x}'

awk is basically C-like and has a small core set of numeric functions built-in. To calculate mean, divide the accumulator result by the built-in variable NR, which is incremented each time a record (line) is processed and so contains the total line count by the time we reach the END block.

Doctests vs unit tests

3:11, Friday February 24th, 2006 • feeling relaxed • no comments

OK, I might have to eat my words here. Doctests are quite cool as small dabs here and there, but the module doesn't have the flexibility of unit tests. It's much harder to chunk the tests and refer to them individually. This is hugely exacerbated by the whole Django model magic madness. Hopefully most of the gymnastics I'm doing in testing at the moment will become redundant when magic-removal hits the shelves. In the mean time I'm considering moving all my tests back to units, which will be a pain because of the whole from django.models... boilerplate that's required everywhere.

Also, having the tests in with code is quite cool in some ways, but it does make getting around the files tricky when the blocks get large. So much for literate programming.

Testing Django apps

4:15, Friday February 17th, 2006 • feeling jubilent • no comments

I've started work on a new, quite large Django project. It will be six weeks until I've implemented everything in the specification, so I wanted to get in early with some tests.

Building on the code and ideas of Hugo, Ian Maurer and Sune Kirkeby, I created a simple Python module that provides:

The result is a simple module that can be used to create either doctests and unit tests that test both models and views. I prefer doctests, because they just seem more pythonic to me. Unit tests are great, but there's a weighty Javaness to them, they're more clunky to write, which is critical. Doctests are also a better fit for Django's model magic. Because of the DB settings monkey-patching, unit tests must import the models after setUp, within each test function. This just adds tonnes of lines of cruft. With doctests, I just have a block of imports at the top of each test docstring.

Web 2.0 logo jam

1:18, Tuesday February 7th, 2006 • feeling relaxed • no comments

Web 2.0 logo jam

There's at least a good few billion in investment here!

Page 11 of 113

← previous page, next page →

Choose another page: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113 or return to the most recent entries.

Last updated at 11:32, Wednesday June 18th, 2008. All times are shown in 24-hour clock format and are BST.

Rate my journal on bloghop.com: the best pretty good ok pretty bad the worst

aftnn.orgafternoon's journal → page 11