C linked list macro

Here’s a simple macro I came up with a few weeks ago for easily defining linked list types in C.

#define LINKED_LIST(type, name)     \
    struct name ## _ {              \
        struct name ## _ * next;    \
        type data;                  \
    };                              \
    typedef struct name ## _ name;

Usage is simple:

LINKED_LIST(int, int_ll);

gives the same type as

struct int_ll_ {
    struct int_ll_ * next;
    int data;
};
typedef int_ll_ int_ll;

Why I dislike PulseAudio (for now)

Before this sounds like a rant, I’d like to first say that I think PulseAudio is a very nice concept, from a technical perspective.  It’s about time Linux got a managable sound subsystem, and some of the features–such as network streaming and synchronised playback–are quite impressive.

However, one thing that really irks me is that, as deployed by major distributions, it appears to enforce the narrow-minded view that a desktop is used by only one person, and that sound is only ever going to play when somebody is logged in to a graphical session.  Anybody who uses MPD has probably experienced the pain caused by this already.  Unfortunately my experience so far with Ubuntu Intrepid is that trying to change this results in even more pain.  Having set up a system-wide instance I’m now in the position where the first time I attempt to play sound works correctly, but any subsequent attempts fail until I kill a per-session PulseAudio instance that has magically spawned (even though I’ve set it not to).  Once the per-session instance is dead, I have no more problems and everything works perfectly until the next time I log in.

I’m currently trialing Fedora 10 on my desktop, so I’ll update this post if I have any more luck there.  Feel free to correct me in the comments if I’m just being stupid or missing something!

Edit: I’ve since fixed this problem: MPD + PulseAudio + Ubuntu Intrepid (8.10).

Yet another blog

The title says it all.  Yet another blog.  And I don’t just mean in the sense of adding more noise to the Internet.  In the time I’ve been maintaining websites, I’ve probably had around 10 things that might be classified as blog-like, ranging through various pre-existing systems (like WordPress) and several self-written content management systems, frameworks, blogs, wikis, etc.

This can be explained by the kind of person I am–I like to work things out, usually from some set of basic principles.  For me, putting a site together using something like Joomla is no fun–the real fun to be had is in actually working out how to write a database-backed content management system with a plugin architecture and theming.  This means that for all personal websites I have a natural tendency to try and write everything myself.  The symptoms are reminiscent of “not invented here” syndrome, yet the cause is different to most.  Most of my projects that fall in this category have been web applications, for some reason.

Which is why using WordPress is a significant step in the right direction for me.  With the time pressures I’ve gained over the past two years, time to work on fun projects is much shorter than before, and the end result is never finishing anything.  If I have a limited amount of time to spend on a project, I spend it on the one that is the most interesting at the time.  Unfortunately, the “interesting” bits tend to die out about 1/3 of the way through most projects, the other 2/3 being hard work to actually mold it into something usable.  When, for example, my blog software is incomplete and not very nice to use because I never got around to finishing the administration interface, I end up not using it, creating yet another stagnant website.  I regularly have ideas for things to write about, but only have about 30 minutes free in which to write them–the downside of wrestling with unfinished software outweighs the smug feeling of “I wrote this”, turning it to “why did I bother?”.  I’ve started giving up on these dead-end projects, moving project documentation to DokuWiki, moving my blog to WordPress, using gitweb instead of my own Git browser, etc.  This is leading me to consider a wider approach of evaluating my projects based on criterias such as “has it been done already?”, “can I get it done in a short period of time?”, etc., and ditching projects which will be a huge amount of effort for little or no gain.  I simply don’t have the time any more.  It’s become painfully obvious that I need to weed out some of my projects to have any hope of producing anything ever.

Still here?  Awesome.  So after that little ramble, let me tell you what this blog should be…  My aim is to generally write about interesting technical stuff I come across that I think like-minded people would be interested in.  What I’m not going to do is use it to ramble on about my own life in general—I’m sure nobody cares.  (Ok, this post was a bad example—I’m tired, it’s to be expected.)  Hopefully along the way I can improve my writing style to be a bit more readable.

Still here???  Wow.  Congratulations—you win one Internet!  Check back later, I might have written something interesting!  (Or use the RSS feed.)

The curse of Firefox extensions

Note: This is a re-post of an article from my previous blog.

Today is my first day of Firefox usage after a three-week break – a break which taught me something…

First, a little background. I’ve been using Firefox since 0.9, and generally its always been the best browser for me. However, recently I lost my taste for it due to the monumental lack of speed it can display sometimes. I mean things like a half-second delay between hitting Ctrl+T and being able to type in the address bar of the new tab, really long page rendering times, etc. I know that Firefox slowness is generally due to extensions, but I relied on most of my extensions. Here is a list of the extensions I can remember having:

  • AdBlock Plus
  • AdBlock Filterset.G updater
  • CustomiseGoogle
  • Download statusbar
  • Firebug
  • Flashblock
  • Foxmarks
  • NoScript
  • QuickRestart
  • Stop Autoplay
  • Stylish
  • Tab Mix Plus
  • Tiny Menu
  • Web developer toolbar

Then I remembered I had tried the Epiphany browser (for GNOME) at some point in the past, and that it had been quite snappy. To put it simply, Epiphany is a browser that uses the Gecko rendering engine, but doesn’t include all the other stuff that slows down Firefox (which I can only assume to be the Extension framework and XUL). The upside is that its blindingly fast. The downside is that you no longer have all the amazing Firefox extensions you’ve become used to. One other advantage over Firefox is that it already has working tag-based bookmarking (slated for Firefox 3.0).

After forcing myself to cope without my extensions for a day, I started to really enjoy the speed and lack of wait-induced stress – Epiphany stays out of my way and gets stuff done really fast. Once I had the momentum, I just kept going. I discovered nice stuff like the fact typing in the address bar also searches your bookmarks as well as your history (something also in Firefox 3.0). Epiphany’s UI is reasonably customisable, but not to the extent that Firefox’s is.

Eventually I had an epiphany (terrible pun, I know…) – I had just survived 3 weeks without the huge number of extensions I came to think I needed in Firefox. I now realised I could go back to Firefox and use it more sensibly. I threw out my old Firefox profile and started again. I now have only the following well-justified extensions:

  • Flashblock – on a laptop, unexpected Flash ads = bye-bye battery life
  • Foxmarks – because I want my bookmarks on at least 3 different machines
  • QuickRestart – no real effect on performance, and sometimes you want to restart Firefox quickly!
Condensed Firefox layout

Condensed Firefox layout

I’m happier with this setup than I was with Epiphany, and it’s a good trade-off between fancy features and responsiveness. One thing I really like about Firefox is the ability to put anything anywhere on the toolbars, and I use a fairly condensed layout, so I was also really happy to go back to the layout I liked.

In my opinion, the best thing to do when deciding if an extension is worth installing is ask yourself the following questions:

  • Does it analyse and/or change what I am viewing?
  • Does it make comparisons against a large whitelist/blacklist?

Extensions doing either of the above will almost certainly slow your browser down to some extent. You will notice that the only content-sensitive extension I have is Flashblock, which is really worth it on a laptop.

Another option is to have multiple Firefox profiles, one of which is clean (like my current setup), and the other having big slow extensions that you sometimes need, like Firebug. Using the -P option to Firefox you can set up a launcher that starts your second profile instead of the default.