It is very nice

Since ripping all my CDs and only buying MP3s, I’ve missed the ability to easily browse my albums when deciding what to play. While I don’t hate iTunes as much as many people seem to, it still turns music into a joyless spreadsheet.

So, given scrolling through lists of data rarely gave me the inspiration that browsing shelves of CDs once did, I came up with a typically laborious and completist solution: make a playlist containing only complete albums and EPs, and finish finding all their cover art.

iTunes albums playlist

It’s not a ground-breaking innovation but it is very nice. It’s easy to scroll through my decades-in-the-making playlist until something grabs me. Much better than looking through a spreadsheet of artist and album titles. I’m re-playing music I’d forgotten I owned, that I forgot existed, that was previously buried away among rows and columns of uninspiring text.

Of course, just as when I used to browse CDs I still find myself thinking, “No, none of these 1,200 albums are quite right.” And this still feels like a solution from the past, for people who miss physical music, and like listening to complete albums, and still buy music occasionally. But I like it.

In Music on 5 September 2015. Permalink

Fixed YouTube favourites

For those of you reading this via my biggest aggregated RSS feed you’ll now start seeing things I’ve favourited on YouTube again.

Given I’m not writing much here, you may as well have everything else I can give, and an occasional video that tickled me in some way is about all there is.

Apparently the YouTube API changed to version three and I only noticed on a rare visit to my own website and noticed recently-favourited videos weren’t appearing. The old PHP code here is pretty old… I just looked, and apparently this version is coming up for ten years.

Anyway, the code is old but I was pleasantly surprised how I was able to get things working again without too much trouble. Well done 2006-me and 2015-me. You’re both better than you think.

2015-me has started rewriting this site again, but at least two other versions of me since 2006-me have attempted that and both ground to a halt under the weight of work and more easily-accomplishable tasks. There are so many moving parts to this site, all of which I want to replicate and improve, that it’s months of work even without distractions. Place your bets.

In Misc on 4 September 2015. Permalink

The natural order of things

This review by Jackson Lears, in the London Review of Books, of The Age of Acquiescence: The Life and Death of American Resistance to Organised Wealth and Power by Steve Fraser is full of good stuff, but only available to subscribers.

I’m fascinated by how societies change over time, and this is about how everyone-for-themselves capitalism has become the only acceptable political position, when there used to be more alternatives. For instance, I had no idea about this:

In the presidential election of 1912, nearly a million Americans - 6 per cent of the electorate - cast ballots for the Socialist Party candidate, Eugene Debs. There were two Socialist members of Congress, dozens of Socialist state legislators, and more than a hundred Socialist mayors. The leading Socialist newspaper, the Appeal to Reason, had more than 500,000 subscribers. And this was only a portion of a much broader swathe of the electorate who considered themselves Progressives or Populists rather than Socialists, but were just as committed to challenging concentrated corporate power in the name of a ‘co-operative commonwealth’.

Which, had I known it at the time, would have made the final section of The Jungle seem less peculiar — lots of excited talk of socialism seemed very odd to me, thinking of America as an entirely capitalist nation.

The review, and the book, look at how left-leaning beliefs have disappeared in the US, mostly over the first half of the 20th century, the Overton Window of mainstream politics moving rightward and shrinking considerably. Capitalism, and a narrow variation of it at that, now appears to be the only possible choice. Anything else is unnatural:

In Fraser’s account, Americans acquiesce in plutocratic rule because they can no longer imagine alternatives to it. In the first Gilded Age, the impact of capitalism was new and strange. Its strangeness made it easier to resist. Attachments to fellow workers and ways of working, memories of an older notion of the public good: they all undergirded popular protest against the capitalist transformation of everyday life. Now the attachments have attenuated, the memories have faded and capitalism has come to seem part of the natural order of things. This growing sense of inevitability has promoted a shift towards what Fraser calls ‘a sensibility of irony and even cynical disengagement rather than a morally charged universe of utopian yearnings and dystopian forebodings’. Now the forebodings persist but (apart from the vague menace of ‘climate change’) they tend to be focused on personal catastrophe: job loss, ruinous illness, economic freefall - all spectres that reinforce compliance with the capitalist order of things. Except on the pseudo-libertarian right, ideological fervour has gone out of fashion.

Much of which sounds familiar in England and Wales too, with big-bank-friendly, social-programme-cutting, privatising policies seen as the only possible “responsible” behaviour among those who lead mainstream parties. The recasting of working peoples’ place in society is, objectively, fascinating, if saddening.

…the few remaining unions have become magnets for resentment, protectors of privileges no longer available to the rest of the population. The ruling class, meanwhile, has redefined itself as ‘the successful’ - a meritocracy that deserves to lead. The widespread acceptance of that notion can be traced, Fraser believes, to the marketing success of three ‘fables of freedom’: emancipation through consumption, freedom through the ‘free agency of work’ and freedom through the heroism of entrepreneurial risk. Together they constitute a collective fantasy that allows many Americans to perceive dispossession as liberation, even as they remain haunted by fears of future insecurity.

I could quote several more paragraphs but that seems a bit off given it’s for subscribers only.

In Periodicals on 30 July 2015. Permalink

What I am, and have been, up to

It’s been a while since I posted anything about what I’m doing, so…

(Summary: I’m freelancing again. It’s fine.)

I left Berg a little over a year ago, shortly before it sadly wound down. I spent a few months last summer trying to work out where I would, ideally, like to work next. During that time I dabbled in the bizarro world of D3.js and spent way too long making a thing that no one, not even me, would find particularly useful. This seems to be a habit.

Towards the end of that summer I joined a new team at Citizens Advice who were starting to work out how to transform all the charity’s digital stuff: how to make their vast quantity of advice more usable and understandable, how to make the public site work better and do more, and how to improve on the tools their employees and volunteers use to help those most in need.

My contract expired at the end of March this year and I decided not to carry on, although the team is now growing and moving on to the next phase. You can see the content and tools we developed over those few months. I wrote the bulk of the code you see there and — taking the usual excuses and embarrassment about one’s own work as read — I’m reasonably pleased with it.

But I think I’m not cut out for working in large organisations like Citizens Advice. I realise the journey to making good, difficult, worthwhile stuff is rarely smooth but I get overly frustrated. The quiet contrariness in me simmers away as I keep my head down and do nothing but the internet typing, and that doesn’t feel like enough (for me to be happy or to be most useful). It’s probably a good thing that I never signed up to work on GOV.UK like so many of my friends; I can’t imagine what I’d have made of the civil service. More than ever, you all have my mystified admiration.

And so, now…? Right now I’m back to freelancing. For the next 2-3 months I’m spending some time with the very lovely folk of Failbetter Games doing front-end development, and the rest of my time putting together a site for another client using Craft, a CMS which looks good so far.

After that? Maybe more freelancing, but I’m not sure.

I first gave freelancing a go back in 2003, when I left UpMyStreet.com, because I had no idea where I wanted to work. I wanted to work somewhere I felt excited about, and eager enough to do a great job, but I couldn’t think where that was. So I tried freelancing and a decade later I was still at it.

(I feel obliged to acknowledge that being able to ponder “where do I want to work?” is an absurd luxury when there are plenty of people with skills and knowledge scrabbling to make any kind of living.)

A dozen years later I feel like little has changed. Freelancing is fine. It’s reasonably varied, and I’m fortunate enough that I seem able to work on fairly interesting projects with nice people and get enough of it. And there’s a simplicity to doing a discrete chunk of work somewhere then moving on. But all the reasons I wanted a change a few years ago still stand:

  • The scale of the work varies little — I usually work on small projects as the sole developer or the sole back- or front-end developer.

  • The work is quite narrow — the client needs x to be built, so there’s less involvement in other aspects of the project than there could be.

  • There’s no chance to build something over the longer term — this is the reverse of the enjoyable “simplicity” I mentioned above. Freelancers are rarely around long enough to see something grow (or not).

  • I’m only briefly part of a team — I won’t be around long enough to see a team change, develop, and learn to work well together over the long term.

  • It’s easy to stagnate — while it’s possible to keep learning new technical skills, there’s little scope to grow in terms of my role, whereas that might be more likely as part of a growing, developing organisation over a longer period.

Of course, this is comparing some bad aspects of freelancing with working in a mythically brilliant organisation. We could just as well compare the many benefits of freelancing with the downsides of the worst permanent roles.

But with that list nagging at me, I’m usually dissatisfied, wondering what it is that would excite me enough that I’d really, really want to join, or really, really want to start. And the longer I carry on with wondering, the higher the stakes feel, and the more perfect something would have to be for me to commit to it.

So, while freelancing is fine, I can’t help but constantly look around, trying in vain to find the place where the grass is not only greener, but, by now, the perfect shade of green. Maybe this is silly. I’ve been looking aimlessly around for so long. Maybe I should accept that standard green grass is fine, that this is fine.

So, that’s what I’m up to. It’s fine.

In Work on 10 May 2015. Permalink

Classic menswear blogs

A good proportion of the time I spend reading things online is devoted to reading about men’s tailoring. This might seem odd, given I’m not exactly a dandy, but I find it fascinating. It’s another world, an escape from reading about technology or current affairs or whatever else.

In case it’s of interest, here are the sites I currently follow. Thankfully they don’t all post frequently. If you know of something not listed here which might be up my street, do let me know.

General blogs

Usually by individuals about the clothes they buy and related topics. Permanent Style and The Sartorial Journal are probably my current favourites. Put This On can be good, but the signal:noise ratio can be off.

Die, Workwear!
By Derek Guy in New York. Lots of ideas, news, details on classic menswear, I think based in New York.
From Squalor to Baller
By Ian Anderson in San Francisco. On his own purchases and outfits, along with general thoughts on suits, shoes, stores, etc.
Grey Fox
By David Evans, UK-based, and aimed at the over-40s. Lots of quite detailed ideas, reviews of clothes, etc. Sometimes a bit more ready-to-wear “men’s fashion” than the others here.
Ivory Tower Style
By David Isle. General posts on classic menswear, accessories and occasionally unrelated things.
The Journal of Style
By Torsten Grunwald somewhere in Europe. Examples of outfits, vintage illustrations, posts about clothes and shoes he owns or is having made.
Men’s Flair
By various London-based authors. Ideas and reviews of their new clothes. Rarely quite hits the spot for me, for some reason.
Permanent Style
By Simon Crompton in London. One of the most popular blogs on these topics. News and reviews, often of Crompton’s own gorgeous and expensive commissions.
Put This On
By a few US-based authors. Prolific. Ideas, reviews, news, quotes, roundups of interesting stuff on eBay, etc. Probably the most like a conventional magazine, but online.
The Sartorial Journal
By Aleksandar Cvetkovic, in London. Visits to tailors and shoe-makers, reviews of suits he’s had made, more general posts. His taste is quite different to mine, but I really enjoy his enthusiasm.
New York-based. General news, ideas, etc. It’s getting really hard to know how to describe and differentiate all these blogs.
The Suits of James Bond
By Matt Spaiser, looking at men’s tailoring through the lens of Bond films. I’m not a huge Bond fan, but it’s still an interesting way to compare and discuss different styles.
Busy Tumblr of well-dressed famous folks from decades past.


Individual tailors

A Tailor Made It
By “Terri … a theatrical costume cutter/tailor at North America’s largest repertory theatre.” So not about clothes one would wear in the real world, but lots of photos and thoughts on costumes during creation.
By “Arno”, with photos of suits etc he’s made for himself (I think; it’s not heavy on description).
Davide Taub
Head cutter at Gieves & Hawkes. Lots of photos of newly-made G&H suits, coats, etc.
Made By Hand
By Jeffery Diduch at Hardwick Clothes in Tennessee, not that you’d know it. Posts about the industry, equipment, and photos of new creations.
Based in Tennessee, Taylor is learning how to design and make his entire wardrobe from scratch, and documenting it here.

Tailors’ shops

These tend to be more self-promotional and so usually less interesting.

Anderson & Sheppard: The Notebook
A blog by one of Savile Row’s tailors, documenting and occasionally promoting goings-on there.
Budd Shirtmakers
By the tiny shop on Piccadilly Arcade. Mostly promotional.
The Cad & The Dandy: The Wardrobe
By the relatively affordable tailors based on Savile Row and in the City. Mainly promotional, with some posts explaining details of styles or giving ideas.
Dashing Tweeds: News
By the makers of interesting modern fabrics and ready-to-wear clothes. Promoting their new products.
David Reeves
New York-based English designer. Some promotional stuff, some nice explanatory posts, although not updated for a few months.
English Cut
By ex-Savile Row, now Cumbria-based cutter Tom Mahon. Mostly promotional stuff, although in 2005 he was way ahead of everyone, with a load of great posts (starting here) about bespoke suits. The first things I read on the topic.
Graham Browne Bespoke
By the relatively affordable City-based tailors. News, photos of new suits, etc.
Richard James: The Row
By the Savile Row tailors’. Mainly promotional stuff, and I’m usually on the verge of unsubscribing.
The Savile Row Tailor
By Steven Hitchcock, Savile Row tailor. A few promotional posts, and others about the details of bespoke tailoring.


Styleforum: Classic Menswear
I think SF is the biggest, busiest forum, way too busy to keep up with. I occasionally dip in and have a browse, and subscribe to a handful of long-running topics. Generally US-heavy.
Ask Andy About Clothes
This claims to be the “most popular”, and is also largely US-oriented. I never get round to looking at this.
The London Lounge
Small, friendly, very knowledgable, London-based. The host, Michael Alden, gathers support for having small runs of fabrics made up.

There we go. It’s a bit like window shopping. Gradually absorbing the names, terms and ideas from an unfamiliar field is a welcome escape or distraction.

In Misc on 5 April 2015. Permalink

Parsing a Wikipedia page’s content with python

A while back I was asking on Twitter and Stack Overflow about how to parse a Wikipedia page’s content using python. It seemed harder than I expected, given the number of Wikimedia-related tools available. Here’s what I ended up doing.

What I wanted to do:

  • Fetch the content of a particular Wikipedia page.
  • Tweak that content (e.g., hide certain elements).
  • Save the resulting HTML.

Given MediaWiki has an API I initially thought the best thing would be to grab structured content using that, remove the elements I didn’t want, then render the rest into nice, clean HTML. This seemed more robust than scraping a rendered page’s HTML, parsing it, removing bits, then saving the remainder. Scraping always feels like a last resort. And there was an API!

But MediaWiki content is much more complicated than I first thought and, following the discussion on my Stack Overflow question, it seemed like turning Wikipedia’s raw wikitext into HTML was going to be more trouble than it was worth.

A small step up from scraping standard Wikipedia pages would be to omit all the stuff surrounding the content, which can be done by appending ?action=render to the URL, e.g. for /Samuel_Pepys. Then it would be a case of parsing the HTML, ensuring it’s sane, and stripping out anything I didn’t want.

The resulting python script (on GitHub, tests) is part of my Pepys’ Diary code, in Django, but is fairly standalone.

The process is:

  1. Fetch the HTML page using requests.

  2. Use bleach to ensure the HTML is valid and, whitelisting only the HTML tags and attributes we want, strip out unwanted elements.

  3. Use BeautifulSoup to further strip out HTML elements based on their CSS class names, and to add extra classes to elements with certain existing classes.

  4. Return the new, improved HTML.

It seems to work alright, resulting in some decent-looking copies of Wikipedia pages.

For completeness, here’s the code at the time of writing, but the GitHub version may be newer:

from bs4 import BeautifulSoup
import bleach
import requests

class WikipediaFetcher(object):

    def fetch(self, page_name):
        Passed a Wikipedia page's URL fragment, like
        'Edward_Montagu,_1st_Earl_of_Sandwich', this will fetch the page's
        main contents, tidy the HTML, strip out any elements we don't want
        and return the final HTML string.

        Returns a dict with two elements:
            'success' is either True or, if we couldn't fetch the page, False.
            'content' is the HTML if success==True, or else an error message.
        result = self._get_html(page_name)

        if result['success']:
            result['content'] = self._tidy_html(result['content'])

        return result

    def _get_html(self, page_name):
        Passed the name of a Wikipedia page (eg, 'Samuel_Pepys'), it fetches
        the HTML content (not the entire HTML page) and returns it.

        Returns a dict with two elements:
            'success' is either True or, if we couldn't fetch the page, False.
            'content' is the HTML if success==True, or else an error message.
        error_message = ''

        url = 'https://en.wikipedia.org/wiki/%s' % page_name

            response = requests.get(url, params={'action':'render'}, timeout=5)
        except requests.exceptions.ConnectionError as e:
            error_message = "Can't connect to domain."
        except requests.exceptions.Timeout as e:
            error_message = "Connection timed out."
        except requests.exceptions.TooManyRedirects as e:
            error_message = "Too many redirects."

        except requests.exceptions.HTTPError as e:
            # 4xx or 5xx errors:
            error_message = "HTTP Error: %s" % response.status_code
        except NameError:
            if error_message == '':
                error_message = "Something unusual went wrong."

        if error_message:
            return {'success': False, 'content': error_message} 
            return {'success': True, 'content': response.text}

    def _tidy_html(self, html):
        Passed the raw Wikipedia HTML, this returns valid HTML, with all
        disallowed elements stripped out.
        html = self._bleach_html(html)
        html = self._strip_html(html)
        return html

    def _bleach_html(self, html):
        Ensures we have valid HTML; no unclosed or mis-nested tags.
        Removes any tags and attributes we don't want to let through.
        Doesn't remove the contents of any disallowed tags.

        Pass it an HTML string, it'll return the bleached HTML string.

        # Pretty much most elements, but no forms or audio/video.
        allowed_tags = [
            'a', 'abbr', 'acronym', 'address', 'area', 'article',
            'b', 'blockquote', 'br',
            'caption', 'cite', 'code', 'col', 'colgroup',
            'dd', 'del', 'dfn', 'div', 'dl', 'dt',
            'figcaption', 'figure', 'footer',
            'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr',
            'i', 'img', 'ins',
            'p', 'pre',
            's', 'samp', 'section', 'small', 'span', 'strong', 'sub', 'sup',
            'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time', 'tr',

        # These attributes will be removed from any of the allowed tags.
        allowed_attributes = {
            '*':        ['class', 'id'],
            'a':        ['href', 'title'],
            'abbr':     ['title'],
            'acronym':  ['title'],
            'img':      ['alt', 'src', 'srcset'],
            # Ugh. Don't know why this page doesn't use .tright like others
            'table':    ['align'],
            'td':       ['colspan', 'rowspan'],
            'th':       ['colspan', 'rowspan', 'scope'],

        return bleach.clean(html, tags=allowed_tags,
                                    attributes=allowed_attributes, strip=True)

    def _strip_html(self, html):
        Takes out any tags, and their contents, that we don't want at all.
        And adds custom classes to existing tags (so we can apply CSS styles
        without having to multiply our CSS).

        Pass it an HTML string, it returns the stripped HTML string.

        # CSS selectors. Strip these and their contents.
        selectors = [
            'div.navbar.mini', # Will also match div.mini.navbar
            # Bottom of https://en.wikipedia.org/wiki/Charles_II_of_England :

        # Strip any element that has one of these classes.
        classes = [
            # "This article may be expanded with text translated from..."
            # https://en.wikipedia.org/wiki/Afonso_VI_of_Portugal
            # eg audio on https://en.wikipedia.org/wiki/Bagpipes

        # Any element has a class matching a key, it will have the classes
        # in the value added.
        add_classes = {
            # Give these tables standard Bootstrap styles.
            'infobox':   ['table', 'table-bordered'],
            'ambox':     ['table', 'table-bordered'],
            'wikitable': ['table', 'table-bordered'],

        soup = BeautifulSoup(html)

        for selector in selectors:
            [tag.decompose() for tag in soup.select(selector)]

        for clss in classes:
            [tag.decompose() for tag in soup.find_all(attrs={'class':clss})]

        for clss, new_classes in add_classes.iteritems():
            for tag in soup.find_all(attrs={'class':clss}):
                tag['class'] = tag.get('class', []) + new_classes

        # Depending on the HTML parser BeautifulSoup used, soup may have
        # surrounding <html><body></body></html> or just <body></body> tags.
        if soup.body:
            soup = soup.body
        elif soup.html:
            soup = soup.html.body

        # Put the content back into a string.
        html = ''.join(str(tag) for tag in soup.contents)

        return html

In Web Development on 25 March 2015. Permalink

Practical Television, February 1952

A while back I bought a copy of Practical Television from February 1952. It’s a fascinating look at a time when TVs were new technology and there were societies of people interested in what we might now call “hacking” with their TVs.

Cover of Practical Television, February 1952There are articles full of circuit diagrams like “From VCR97 to Magnetic-2; Converting a Receiver for Standard Tubes” and “Modifying the AN/APR-4”. There are also lengthy tips on getting the most from your Murphy Receiver and how to make a slotted indoor aerial for “fringe area reception without an elaborate outside array.” (There’s a lot of mention of “fringe areas” as presumably signal coverage was patchy.) It also has plenty of adverts for components and tools — valves, face plates, scanning coils, test meters — but none at all for televisions themselves.

For some context, one report mentions that in nearly three years the number of television licenses (required to own a TV set) has increased from 285,500 to 1,113,900, which is still less than 5% of today’s number. This is around 16 months before the coronation of Queen Elizabeth II which, in Britain, is seen as the moment TV-watching hit the big time. There was only a single TV channel to watch, the BBC, and it only broadcast for a few hours each day.

I’ve uploaded a scan of the magazine to the Internet Archive, and have also pulled out a few of the most interesting snippets below…

From “Televiews”, the introductory editorial page:

Some of the Sunday newspapers have been criticising a BBC producer because he declines to devote programme time to a talk on breathing as an aid to health. Some time ago this same producer was in trouble with the doctors because of his broadcasts on slimming for women. Perhaps this has made him cautious. We, however, support his decision for we do not believe that a talk on correct breathing would have been of interest since it is taught in every school.

From the “Telenews” section:

Interference from Lights

According to a Midlands electrical contractor, Mr. S. Dagnall, interference on television screens over the Christmas period may have been caused by the on-and-off flashing of fairy-lights on Christmas trees.

Suppressors could be fitted, but only at a cost of between 15s. to £1, and as this was not considered worth while, Mr. Dagnall refused to sell the lights.

Cinema’s Ally

Mr. J. Goodlatte, chief of the ABC cinema circuit, believes that the effect of television on box office takings in this country is only slight.

… Mr. Goodlatte praises the everyday housewife and places her second only to the films themselves as the cinema’s greatest ally. After a hard day at home it is she who most wants to go out for her entertainment.

Television Tape Recordings

It was recently announced in Hollywood, California, that a method of recording television images on a magnetic tape is expected to be ready for commercial use in a few months.

This system is the result of two years of research, financed by Bing Crosby.

Viewing in the Clouds

A British firm are planning a receiver for installing in airliners, to provide entertainment for passengers.

The biggest snag would be interference from the engines.

Appeal from the BBC

The BBC recently appealed for better behaviour from patrons at televised outside events where candid cameras take close-ups of crowds or where commentators hold interviews with people surging in the background.

Some viewers have complained about hand-waving or face-pulling from people who should know that they can be seen at home.

From “Underneath the Dipole”, subtitled “Television Pick-ups and Reflections”:

What a magnificent array of talent took part in the TV Christmas Party. Norman Wisdom, recently returned from America, … proved that his particular line of comedy is well suited to TV. When he was in America, he took a trip to Hollywood for a “look around,” and amongst other things was shown a television set by Stan Laurel which gave a choice of twelve programmes — most of them absolutely first-rate in entertainment value.

From “Here and There”:


An announcement is expected shortly from The Television Sports Advisory Committee concerning efforts that are being made to reach some agreement over the televising of sporting events.

The committee is expected to favour the broadcasting of all forms of sport and, if necessary, to televise only parts of matches, events or meetings should promoters not favour the transmission of whole programmes — that is, the first or second half only of a football match or one period of an ice-hockey game.

Some sporting associations have had no objection in the past to the televising of complete relays — the Lawn Tennis Association and the Rugby Union, for instance — but most promoting bodies feel that though the idea may have advertising qualities, the relaying of a complete afternoon’s sport would affect attendances and cash losses would be the inevitable result.

If only they could see how much sport broadcasting deals bring in today.

And finally:

“American Menace”

In a cable from California, U.S., where he is staying, “Wee Georgie Wood,” considers television in the United States to be a “menace to the country.”

That is the item in full.

In Television on 15 February 2015. Permalink

Recent comments on writing

Writing archives by category