allenap

0 notes

Don’t write shell scripts

Command substitution errors are silently ignored whenever the substitution occurs in a command:

$ echo $(false); echo $?
0
$ variable=$(false); echo $?
1

Not when setting variables. Course not.

When I say don’t write shell scripts, I’m talking mostly about sh and bash, but every shell I’ve used has fairly arcane rules that need to be followed. The convenience of the shell, its brevity, especially when creating pipelines, is manifested through these rules, but they’re numerous and complex enough to regularly trip up and confuse even experienced folk.

After spending years writing shell script - including one >1000 line bash script that has been running in production for ~10 years - I now strongly think that shells, like bash, should only be used interactively, and not for any kind of automation, or even the very thinnest of glue.

The second finest shell script in the universe is a single line long:

exec $something_else

The finest… does not exist.

0 notes

To me, a lifestyle business doesn’t equate to running a tiny business as an alternative to having a job. A lifestyle business doesn’t have to be small at all, either in revenue or employees. The main requirement of a lifestyle business is just that it allows the entrepreneur/owner to live how he or she wants to live now, while running the company.

Startup vs. Lifestyle Business (a Short Comparison from a Guy Who’s Done Both)

There’s some interesting stuff in the comments too.

0 notes

Product or service?

I once tried to be an entrepreneur.

I moved to Luxembourg with my wife, set up a company, and then wondered what I was going to do. I couldn’t decide if I should build a product of some sort - and then, what? - or if I should provide services. Predictably, I floundered for a few years.

I suspect I’d have made a better job of it had I been able to read What Should You Do With Your Crappy Little Services Business? on TechCrunch, and the comments on Hacker News. I see now that I have a strong bias against providing services, but that services - by which I mean things like bespoke development, system administration, and so forth - might actually be a better fit for my life, especially now I have kids.

2 notes

On Launchpad we agonize about going read-only for 60-90 minutes a month to make database changes. Waitrose, however, have quite a different idea.

They’ve built a new website:

…you can continue to shop at Waitrose.com as normal.

However, in order to allow us to transfer your details over to the new website, you will be unable to make any changes to your Waitrose.com Account, including your billing details and delivery address, between the 28 February to the 11 March 2011.

I can think of reasons why they might plan a migration this way, but I can’t think of any that actually justify it. They are mucking around with their customers - grocery shoppers - for 11 days. After which the customers will be left with a website which they can probably no longer navigate, and is likely to be full of bugs.

2 notes

Script to control native Spotify on Linux

Almost the simplest possible Python script to control the native Spotify client on Linux:

#!/usr/bin/env python

import dbus
import sys

if __name__ == '__main__':
    session = dbus.SessionBus.get_session()
    spotify = session.get_object(
        "org.mpris.MediaPlayer2.spotify",
        "/org/mpris/MediaPlayer2")
    for command in sys.argv[1:]:
        getattr(spotify, command)()

Use like:

$ spotify-control PlayPause
$ spotify-control Next
$ spotify-control Previous

I was helped by reading Playing with D-Bus interface of Spotify for Linux.

Filed under python spotify dbus

1 note

I tried appending “/rss” to the URL of one of my tag archive pages, and somewhat to my surprise, it worked.
Per-tag RSS feeds for Tumblr by Paul Mison.

(Source: notes.husk.org)

2 notes

Tagging installed Python libraries

Generating TAGS for the project I’m working on with the addition of an installed library - Twisted for example - can be a pain:

$ python
>>> import twisted
>>> twisted.__file__
'/usr/lib/python2.6/dist-packages/twisted/__init__.pyc'
>>>
$ etags -R src /usr/lib/python2.6/dist-packages/twisted

I got bored of that.

Enter pyctags to take the pain away:

$ pyctags -e -R src py:twisted

It’s a pretty simple script:

#!/usr/bin/env python

from imp import find_module
from os import execvp
from os.path import dirname
from sys import argv, stderr


def expand(arg):
    if arg.startswith("py:"):
        module_name = arg[3:].replace(".", "/")
        try:
            return find_module(module_name)[1]
        except ImportError:
            stderr.write("Could not expand %r.\n" % module_name)
            return arg
    else:
        return arg


if __name__ == '__main__':
    args = ["ctags"]
    args.extend(expand(arg) for arg in argv[1:])
    execvp("ctags", args)

Filed under canonical python

1 note

Free ticket folly

Norwich drivers asked to take the bus

Norwich has been selected as a pilot for a nationwide scheme to get people to swap one in every 25 journeys from their car to the bus … To help make the vision a reality, a million free bus trips are being given away nationally to get car drivers on board.

I know what the bus is like, thanks, and a free bus journey is not going to change my mind. It’s going to help out people who were going to take the bus anyway.

Just one double-decker bus can take 75 cars off the road.

Yes, if it’s full, if you’re under 5’6” tall or willing to have both legs or your head amputated, if you want to sit next to a soap dodger or on the previous soap dodger’s seat crud, if you want to catch or spread the latest flu virus, if you want to arrive an hour later or leave an hour earlier than your friends, and you really like to ignore your comfortable, convenient, self-controlled seat/radio/ventilation/heating/aircon equipped, already budgeted car sitting at home.

The millions spent on this campaign might be better spent, say, hiring some people who hate buses to design a bus service they would use.

Giving away free tickets is throwing the money into the wind.

1 note

My issues with PayPal

Sean Murphy on Identi.ca asked me:

What don’t you like about PayPal?

There are several factors, most stemming from their ubiquity/monopoly in the web payment area that forces me to use them:

  • Site full of stupid usability issues; I don’t want to trust my money/details to something so broken,
  • Every time I log in there’s another hurdle to jump before I can get my money, move some money, etc.
  • Closed world, no competition within the PayPal world; take it or be outside of it,
  • Many stories about PayPal withholding money; banks can be abusive too, but I can take my business elsewhere.

That’s about all I can think of for now, or other reasons are variations on the above. My displeasure earlier today was triggered by the first of those points.