Alt-J – Greasemonkey script to replace Wingdings

Here’s a Greasemonkey script to get rid of those horrible “J” characters we see when an Outlook user tries to send you a smiley.

(Thanks to Abhinay Omkar’s “J for Smile” script which was the inspiration here.)

I don’t really use Greasemonkey but it seems that most people put their scripts on – however this seems to be a repository for Chinese spam and other garbage. So here it is:

// ==UserScript==
// @name        Alt J
// @namespace
// @description Replace J with smiley etc
// @include*
// @grant       none
// @version     1
// ==/UserScript==

function makeSmiley(sm)
        case "J":
        return "☺";
        case "K":
        return "😐";
        case "L":
        return "☹";
        return sm;

function makeSmileys(){

    var fonts = document.getElementsByTagName('font');
    for (var key in fonts)
        var font = fonts[key];
        if (font != null) 
            var face = font.face;
            if (face != null && face.indexOf('Wingdings') != -1)
                font.innerHTML = makeSmiley(font.innerHTML);

    var spans = document.getElementsByTagName('span');
    for (var key in spans)
        var span = spans[key];
        if (span != null) 
            var style =;
            if (style != null && style.indexOf('Wingdings') != -1)
                span.innerHTML = makeSmiley(span.innerHTML);

Posted in Uncategorized | Leave a comment

C stdio – disable buffering

Sometimes it’s useful to disable buffering for printf/fprintf etc. This is especially the case when you’re trying to debug a program and you’re not sure if it’s going to exit prematurely, before the output buffer gets flushed.

It’s a pain to stick fflush() after every fprintf. The proper way to do it is:

setbuf(stream, NULL);

The manpage assures us this is equivalent to the more verbose

setvbuf(stream, NULL, _IONBF, BUFSIZ);
Posted in Uncategorized | Leave a comment

Array equality in JavaScript – functional style

So it turns out there is no built-in test for array equality in JavaScript. There are some suggestions here on StackOverflow, but I wanted to see if there was a simple answer using Functional Javascript.

Here’s my attempt:

ArrayEq: function(a1,a2) {
    return reduce("x && y",true,map("x[0]==x[1]",zip(a1,a2)));

Reading from right to left, the zip transforms them into an array of pairs, then each pair is compared, and then the reduce applies the && operator to each boolean result in turn.

Posted in Uncategorized | 1 Comment

Quick random passwords

I’m sure there are lots of password generators out there, but a quick way of achieving this at the command line is something like

cat /dev/urandom | dd count=1 2> /dev/null | base64

Then copy and paste as much as you need. The result will be fairly unmemorable, but apart from OS login passwords which need to be typed, most logins can be automated, eg by using user:pass@host style URLs.

Posted in Uncategorized | Leave a comment

How do I store long strings with Firebird, NHibernate and NHibernate.Mapping.Attributes?

Yes, I know, it’s the hot question of the moment which everyone is asking.

Anyway, I figured that someone else might want to know this, since Firebird is a supported database for NHibernate, and the embedded version is very handy.

This is what the declaration for a member called “Detail” should look like (I think you can omit the “Name” attribute if you want):

[Property(0, Type="StringClob")]
[Column(1, Name="Detail", SqlType = "BLOB SUB_TYPE 1")]
public virtual string Detail { get; set; }

So the SqlType bit is Firebird-specific, and I don’t think it was very obviously documented anywhere in the Firebird docs. It feels a bit nasty to write code like this because it means I’m locked in to one database backend FOREVER.

For a fun bonus rant, the NHibernate page seems to be down at the moment. You can say what you want about Java, but the open-source tools and community are so much richer for Java than they are for C#. In fact, I’d say that C# is at around the Java 1.2 level on this basis.

Posted in Uncategorized | Tagged , | Leave a comment

Richard Stallman’s Rider

Thanks to The Register, whose story linked to an email which details RMS’ rider and requirements for making speeches in tedious detail.

Honestly, this stuff makes “a bowl of blue M&Ms” look trivial. We learn that he doesn’t like dogs, can’t sleep if the temperature is higher than 22°C, and that “I like some wines…but I don’t remember the names of wines I have liked”.

Even if I thought this guy was the messiah of free software (I am an avid emacs user), I don’t think I would want to host such a fussy and childish person.

Posted in Uncategorized | Leave a comment

Small change: the economics of charging for trivial things

I got thinking about this subject because Fred Baker Cycles had the temerity to charge me 50p for the use of their bike pump.

This was definitely adding insult to injury as I was confronted with a flat tyre after having visited the dentist. No problem, I thought, I’ll just go to a local friendly bike shop and at least be able to ride the damn thing home.

Maybe I’m too sensitive to petty things, but charging 50p for this service (I grudgingly handed over my equilateral curve heptagon – I had no other choice) generated a huge amount of badwill (the opposite of goodwill) towards this shop.

Contrast this approach with Orange retail stores (disclaimer, I once worked for them), who will charge your mobile phone, gratis – you don’t even have to be a customer.

Maybe it’s something specific to bike shops. So many of them have a reputation for being rude and unhelpful, and if these Google reviews are anything to go by, this one is no different.

Posted in Uncategorized | 1 Comment

Emacs: how to search and replace newlines

I can’t remember where I learnt this, but I use it all the time and it’s not at all obvious.

When in the minibuffer (at the prompt for replace-string or replace-regexp, for example), enter C-q C-j for a newline (0x0D, NL).

Depending on the coding system for the buffer (DOS mode for example), you may also need to use C-q C-m for carriage return (0x0D, CR) – suddenly it makes sense where all those ^Ms come from!

Posted in Uncategorized | 3 Comments

C++: Mixing containers and inheritance

This is the sort of thing in C++ which catches me out as a recovering former Java programmer.

Amongst the very good advice I was given whilst learning C++ was:

  1. Use the STL containers
  2. Only use pointers when you really need to

The first point is sound advice, after all, why re-invent the wheel? There are plenty of useful containers like std::vector in the library.

The second point is about memory management. It’s much better to let scoping and destructors do the work for you, rather than keeping track of pointers and calling delete().

With this in mind, here’s a sample program:

#include <iostream>
#include <vector>

class Animal
    virtual void hello();

class Dog : public Animal
    virtual void hello();

void Animal::hello()
    std::cout << "<Generic Animal Noise>" << std::endl;

void Dog::hello()
    std::cout << "Woof" << std::endl;

int main()
    // store the object directly
    std::vector<Animal> animals;

    // store the pointer
    std::vector<Animal*> animalPtrs;
    animalPtrs.push_back(new Dog);

What’s it supposed to print? Well I thought it should print


but instead it prints

<Generic Animal Noise>

I was genuinely surprised by the result – the lesson here is to use pointers if you don’t want your class to lose its identity.

This was also discussed in this forum post and (in great detail) in “STL and OO Don’t Easily Mix”.

Update: Apparently this behaviour is called slicing. Well I really have learnt something today.

Posted in Uncategorized | Leave a comment

Fame at last!

Check out this review of Sacha’s Morbid Atrophy album Grist ‘n’ Grind (warning: contains Flash).

My favourite excerpt: “‘A Porter Too (Blench mix)’ is seriously an amazing piece of work”

Posted in Uncategorized | 2 Comments