15:57 GMT, looking south-west |
Tuesday, 31 December 2013
Monday, 30 December 2013
Wednesday, 25 December 2013
his'n'hers carbon sequestration
Labels:
algorithm,
books,
Christmas,
complexity,
computer,
graphics,
mathematics
Here are our Christmas presents to each other. They are books. (There are other types of presents?) The rule is: a book we want, but (probably) would not buy for ourselves. This criterion is almost certainly impossible for the other to determine, so we suggest options to each other.
Tuesday, 24 December 2013
many people would rather fail than change
Evidence-based software engineering? Surely not!
For all my social networking posts, see my Google+ page
For all my social networking posts, see my Google+ page
Monday, 23 December 2013
Friday, 20 December 2013
vaccinate
Labels:
medicine
I got most vaccines as a child. I do remember getting chicken pox, though. It wasn’t nice.
Growing Up Unvaccinated tells a story more people need to hear.
For all my social networking posts, see my Google+ page
Growing Up Unvaccinated tells a story more people need to hear.
If you think your child’s immune system is strong enough to fight off vaccine-preventable diseases, then it’s strong enough to fight off the tiny amounts of dead or weakened pathogens present in any of the vaccines.
For all my social networking posts, see my Google+ page
Thursday, 19 December 2013
tormenting students
I’ve just used the phrase “mentoring students” in a document. The spell checker doesn’t recognise “mentoring”, and suggests “tormenting” instead.
Hmm. Should I accept the suggestion?
For all my social networking posts, see my Google+ page
Hmm. Should I accept the suggestion?
For all my social networking posts, see my Google+ page
Tuesday, 17 December 2013
compiler shavings
Mike Hoye provides an interesting bit of computing history, plus an Open Source rant.
For all my social networking posts, see my Google+ page
the reason we started using zero-indexed arrays was because it shaved a couple of processor cycles off of a program’s compilation time. Not execution time; compile time.
For all my social networking posts, see my Google+ page
Friday, 13 December 2013
wallpaper your apartment in tinfoil
Labels:
computer
Charlie Stross: Trust Me (I'm a kettle).
Just because you’re paranoid doesn’t mean they aren’t out to get you.
For all my social networking posts, see my Google+ page
Just because you’re paranoid doesn’t mean they aren’t out to get you.
For all my social networking posts, see my Google+ page
Thursday, 12 December 2013
outside looking in
Labels:
astronomy,
moon,
space flight
Something even better than Sagan’s “Pale Blue Dot” for putting things into perspective?
Juno records Earth-Moon orbit.
For all my social networking posts, see my Google+ page
Juno records Earth-Moon orbit.
For all my social networking posts, see my Google+ page
Wednesday, 11 December 2013
Beautiful Soup
A while back I changed some of the design of my website to using more CSS. This left quite a few pages with an <HR> (horizontal rule) at the bottom. This was the previous way I gave a visual indication of end of the page. With the new CSS styling, this isn’t needed. But how to remove them all? My website has over 21,000 files. Okay, it’s not that bad: there are only just over 1000 html files that are not auto-generated. Nevertheless, there’s no way I was going to search and edit 1000 files by hand. I’d need to write a program. A program that could parse and edit html.
In my wanderings, I stumbled across Beautiful Soup, a Python library designed to do just that. I had a little spare time today, so I thought I’d investigate it. A little while reading the documentation (yes, really!), and I’d written and tested the <HR> remover:
Emboldened by this, I thought of the other change I wanted to make: fix up the ALT/TITLE mess in my IMG tags. In the early days of my website, I was using the ALT tag not only as an actual ALT tag, but also as a stand-in TITLE tag. This was because I’d noticed that the ALT text appeared as hover text in the browser I was then using. I’d thought that was how it was supposed to work, because I didn’t read the documentation (yes, really). Later I discovered the difference, and have recently been using ALT and TITLE properly. Also, I hadn’t bothered to give ALT tags to images that are merely decorative, but I’ve recently learned that they should have ALT="" to be properly skipped by screen readers. So I wanted to fix that, too. So, back to Beautiful Soup, to write an <ALT> modifier.
Easy peasy. Now all I had to do was loop over all the files in the directory structure. Naturally, there’s a library for that.
Well, actually, that’s not quite it. The thing that gave me the most grief was the unicode aspects. My first attempt to write the file back out resulted in mangled non-breaking spaces and bullet characters, which were being written out in Unicode, not as html entities. A bit of hunting around on the web led as ever to the invaluable Stack Overflow site, which pointed me in the right direction. After a bit of fiddling, I wrote the adequate, but not totally perfect, solution of:
I ran the code over (a copy of) my website. It looked at 3690 files, opened the 1076 ones of them that were html, and updated 853 of them, all in about 5 seconds.
I love Python (and all its libraries).
I’m not so keen on Unicode.
In my wanderings, I stumbled across Beautiful Soup, a Python library designed to do just that. I had a little spare time today, so I thought I’d investigate it. A little while reading the documentation (yes, really!), and I’d written and tested the <HR> remover:
from bs4 import BeautifulSoup
def delete_final_hr(soup): changed = False all_tags = soup.find_all(True) if not all_tags: # should never be a tag-less file, but... return changed final_tag = all_tags[-1] if final_tag.name == u'hr': final_tag.decompose() changed = True return changedFind all the tags. If the final one is an <HR>, remove it. And that’s it!
Emboldened by this, I thought of the other change I wanted to make: fix up the ALT/TITLE mess in my IMG tags. In the early days of my website, I was using the ALT tag not only as an actual ALT tag, but also as a stand-in TITLE tag. This was because I’d noticed that the ALT text appeared as hover text in the browser I was then using. I’d thought that was how it was supposed to work, because I didn’t read the documentation (yes, really). Later I discovered the difference, and have recently been using ALT and TITLE properly. Also, I hadn’t bothered to give ALT tags to images that are merely decorative, but I’ve recently learned that they should have ALT="" to be properly skipped by screen readers. So I wanted to fix that, too. So, back to Beautiful Soup, to write an <ALT> modifier.
def update_alt(soup): changed = False all_img = soup.find_all('img') for img in all_img: if 'alt' in img.attrs: if 'title' in img.attrs: # both present, do nothing pass elif img['alt'] != '': # non-empty alt only, copy to title img['title'] = img['alt'] changed = True else: if 'title' in img.attrs: # title only, copy to alt img['alt'] = img['title'] changed = True else: # neither; make an empty alt img['alt'] = '' changed = True return changedFind all the image tags. For each tag, if there’s both an ALT and a TITLE, do nothing; if there’s only a (non-empty) ALT, copy its text into the TITLE; if there’s only a TITLE, copy its text into the ALT; if there’s neither, make an empty ALT. And that’s it!
Easy peasy. Now all I had to do was loop over all the files in the directory structure. Naturally, there’s a library for that.
import os
path = '~susan' for root, dirs, files in os.walk(path): for name in files: if name[-4:] == '.htm': changed = False path_name = os.path.join(root, name) with open(path_name) as file: soup = BeautifulSoup(file) changed = delete_final_hr(soup) or changed changed = update_alt(soup) or changed #write out the modified file, in ascii if changed: with open(path_name, 'wb') as file: file.write(convert_to_entity_names(soup))Walk the directory structure. For each file, if it is an html file, read it into soup, delete the final <HR>, update the ALT/TITLE fields; if this has changed the file, write it back out. And that’s it!
Well, actually, that’s not quite it. The thing that gave me the most grief was the unicode aspects. My first attempt to write the file back out resulted in mangled non-breaking spaces and bullet characters, which were being written out in Unicode, not as html entities. A bit of hunting around on the web led as ever to the invaluable Stack Overflow site, which pointed me in the right direction. After a bit of fiddling, I wrote the adequate, but not totally perfect, solution of:
def convert_to_entity_names(soup): ascii = soup.encode('ascii', 'xmlcharrefreplace') ascii = ascii.replace(' ', ' ') return asciiAnd that really is it!
I ran the code over (a copy of) my website. It looked at 3690 files, opened the 1076 ones of them that were html, and updated 853 of them, all in about 5 seconds.
I love Python (and all its libraries).
I’m not so keen on Unicode.
Tuesday, 10 December 2013
Trello for tablets
Labels:
Trello
I use Trello daily, and now my tablet version no longer looks like a really big phone version. Yay!
For all my social networking posts, see my Google+ page
For all my social networking posts, see my Google+ page
failing to sequester carbon, once a year
Labels:
Christmas
Well, that’s the Christmas cards done for another year.
Being able to print address labels removes the chore aspect, and makes the exercise an enjoyable one of thinking about each of the recipients: who gets which card, and why? (Recipients, please don’t overthink this when you see your card: you get the most appropriate one for you, subject to the invisible-to-you constraints of our available pool of cards.)
Being able to print address labels removes the chore aspect, and makes the exercise an enjoyable one of thinking about each of the recipients: who gets which card, and why? (Recipients, please don’t overthink this when you see your card: you get the most appropriate one for you, subject to the invisible-to-you constraints of our available pool of cards.)
I can safely say this represents more letters than we produce in the entire rest of the year put together. |
Friday, 6 December 2013
Sunday, 1 December 2013
that's not in the least bit suspicious
Labels:
Bonnie Tyler,
computer,
web
Our internet connection at home travels along the same piece of wet string as does our phone line. (I’m assuming it’s wet string, based on the bandwidth it achieves.) Recently it’s been a bit glitchy, dropping out at random moments. Then the other day I spotted a correlation: it drops out when the phone is in use. This hasn’t always been the case: I’ve been on the phone to support while using my machine, so this is something new.
We spent a while trying to narrow the problem down. Was it answering, being connected, or hanging up the phone that triggered the event? No, it was simply calling the number. Was it one of the filters separating the phone and internet signals? We tried swapping in and out these gadgets. Eventually we had pared the system down to a single filter, with no handsets even connected. Same problem. Either all 7 filters are broken (not totally implausible, they are cheapo dinguses, all over 10 years old), or the problem lies elsewhere.
What will probably look weird, if not downright suspicious, to anyone monitoring us (not that anyone would do such a thing, obviously...) is what was visible from outside. To see when the network went down, we watched the blinkenlights on the router. To load the network during tests, we downloaded a YouTube video, let it play about halfway through to check the network was stable, then called the landline from a mobile, which stopped the network.
The result of this is that we downloaded the same YouTube video, and interrupted its download halfway with a call from a mobile, about 20 times. Moreover, because the network connection dropped out, it would re-establish with a different IP address each time, as provided by our ISP.
Oh, and what was this ultra-suspicious video? Bonnie Tyler’s Total Eclipse of the Heart, obviously.
What will probably look weird, if not downright suspicious, to anyone monitoring us (not that anyone would do such a thing, obviously...) is what was visible from outside. To see when the network went down, we watched the blinkenlights on the router. To load the network during tests, we downloaded a YouTube video, let it play about halfway through to check the network was stable, then called the landline from a mobile, which stopped the network.
The result of this is that we downloaded the same YouTube video, and interrupted its download halfway with a call from a mobile, about 20 times. Moreover, because the network connection dropped out, it would re-establish with a different IP address each time, as provided by our ISP.
Oh, and what was this ultra-suspicious video? Bonnie Tyler’s Total Eclipse of the Heart, obviously.
Subscribe to:
Posts (Atom)