Adventures in bookmarklet land

Do you use bookmarklets? They're little bits of javascript that you save as bookmarks, that do something to the page you're on when you click on them. Today I made a bookmarklet to change the formatting on any Project Gutenberg HTML book.

To see it in action, drag this link to your bookmarks bar: Format Gutenberg - then go to any Project Gutenberg book as an HTML page - try this one to begin with - then scroll down to the main text and click on your bookmarklet.

A bit of background:

I read and wrote a lot of fanfiction as a teenager, and (I suppose largely out of nostalgia) have some particular preferences about text formatting. Nowadays, I find 13px Verdana on a white background, with minimal margins and no indenting, to be the easiest to concentrate on. People talk a lot about how it's difficult to read from a computer screen (hence the rise of e-ink) but personally I suspect it's easier for me to read fiction when it's just another tab on my browser. Project Gutenberg is a massive online library of out-of-copyright literature.

I'm moving house this weekend, my exams start this Wednesday and in general, I'm pretty stressed out. I'm having a quiet evening watching comedy with my brother Pete and, as usual when I'm under pressure, obsessively coding. I've always thought bookmarklets were pretty cool (if fairly mysterious), so I had a look at some source code and had a go at working it out (I'm sure there are lots of tutorials on the internet, but I was looking for a puzzle).

My general strategy and some code: Continue reading Adventures in bookmarklet land

...

Lately I've been...

Front cover of The Tao of Pooh and the Te of Piglet...reading The Tao of Pooh and the Te of Piglet by Benjamin Hoff. I thought it might be a pretty interesting read - what better way to learn about a religion than through irreverent Winnie the Pooh quotes? Well, I've been enjoying the quotes immensely, but so far the book itself hasn't impressed me in the slightest. It's full of snide remarks about "dessicated scientists" and basically makes the point that you can't understand the natural world unless you completely avoid studying it in depth. The idea that further knowledge about a thing makes it less beautiful is truly abhorrent to me as a scientist... and as a human being.

...not so much reading as flipping through Cooking For Geeks by Jeff Potter - which, in contrast, is a wonderful book that completely demystifies all of the processes that we use in the kitchen.

...listening to podcasts of Marcus du Sautoy's Radio 4 series, A Brief History of Mathematics. He very approachably describes the key ideas in the history of maths, and the people who came up with them (or discovered them, I suppose, depending on your viewpoint). They've come in handy while I've been...

...running the Couch to 5k Program for the last three months or so. I'm only at the end of Week 7 of the schedule (I've had to repeat a lot of days!) but I've ran further and longer than I ever have before, and I feel great!

...programming some bioinformatics applications in Python. One which converts an amino acid's pKa to the fraction which will be protonated at a range of pHs (source code), one which uses a whole protein sequence to find the pH at which it will have zero charge (source code) and, most recently, taking biological data from several databases and collating them into linked HTML pages (source code and essential module). The programming lessons section of my degree has been fantastic, I'm quite sad that it's nearly over.

...knitting Christmas decorations for my house and making some homemade Christmas presents. But let's not spoil the surprise :)

...

Awk! Awk! Awk!

This week in between lots of Python and maths and things, I have been learning about awk. Awk is a programming language for doing stuff to text files that consist of columns of data. You can use awk at the command line.

awk '<condition> {<command>}' ./<filename>

will execute <command> on lines in the file called <filename> that meet <condition>. So if you want to print out all the lines that contain the word "banana", you would type

awk '/banana/ {print $0}' ./<filename>

Enclosing "banana" in / asks awk to search for it. Awk uses dollar symbols to refer to columns. $1 is the first column, $2 the second, and so on. $0 refers to the entire line.

awk '$1 == "10"{print $2}' ./<filename>

will print out the second column of all the lines on which the first column says "10"

...