Archive for August, 2007

Compiling ejabberd on Ubuntu

Friday, August 31st, 2007

Following on my previous post, the next stage is to add an XMPP server to the setup, in the form of ejabberd. As before, all the commands given are executing from our home directory, and in every case ubuntu01 should be substituted with the hostname (fully qualified) of the machine.

(more…)

Compiling Erlang on Ubuntu

Thursday, August 30th, 2007

For playing with distributed stuff, I’m using a bunch of Ubuntu ‘machines’ running under VMWare Server. There’s no particular reason for using Ubuntu other than that I happened to have a VM image (Ubuntu-6.06.1-desktop-i386) kicking around already, and it’s not really necessary to compile as packages are available, but I prefer it that way. Anyway, for reference, here is a quick guide to compiling Erlang from the starting point of a basic Ubuntu installation:

  1. From your home directory, get the Erlang source: wget http://www.erlang.org/download/otp_src_R11B-5.tar.gz
  2. Unpack it: tar -xzf otp_src_R11B-5.tar.gz
  3. Get a working gcc: sudo apt-get install build-essential
  4. Get the ncurses development libraries: sudo apt-get install libncurses5-dev
  5. Get m4: sudo apt-get install m4
  6. Optionally, get the ssl libraries: sudo apt-get install libssl-dev
  7. Go into the erlang source directory: cd otp_src_R11B-5
  8. Run the configuration script: ./configure
  9. Compile it all: make
  10. Install it: sudo make install

The above should all go smoothly, leaving you with a working Erlang setup. To confirm this, type erl to get an Erlang prompt.

Audidiocy

Tuesday, August 28th, 2007

As I noted previously, I have Merlin Mann to thank for my current level of inbox efficiency. To add to that, today he was responsible for a very hearty chuckle indeed, when I stumbled across this, which is ridiculous in so many ways I don’t even know where to start. From what I can gather, it isn’t meant to be funny.

Chicks and Mnesia

Friday, August 24th, 2007

Two quick snippets of unrelated randomness:

1. The things that were recently tasty eggs are now cute chicks, as of last Sunday, hence the picture. Only two though - one yellow, one black. The majority weren’t even fertile this time around, so perhaps Fred is losing his touch.

2. I was planning to go to bed two hours ago, then I started playing with Mnesia, which is Erlang’s distributed database. Very interesting indeed, but I need to stop doing it immediately and go to sleep instead.

The Western Frontier

Friday, August 17th, 2007

There seems to be an overdose of techy stuff being written here lately. Let me rectify that with a demonstration of my defensive measures on our western frontier:

As you can see, it’s the perfect outpost for taking potshots at anyone attempting an invasion from that direction, and since our neighbour that way is a bona fide knight of the realm it seems wise to be prepared. I’m convinced my solid construction will withstand his lance long enough for me to hit him squarely on the nose with a plum* or two.

The original plan was to have the hatch open outwards, landing horizontally on the hedge and thus forming a perfect place to set your drink down, but it was a bit tricky to get the hinges in the right place and in the end, frankly, I couldn’t be arsed.

*We are paddling in the pesky things at the moment. If you like plums, feel free to come and get some. Unless you’re a knight.

YAW(N)S

Friday, August 17th, 2007

Last post on this subject for now, hopefully, since even I’m getting bored of it. Just for the sake of completeness, I did the ISO date formatting ‘properly’, as follows:

w3cdtf(GregSecs) ->
	Date=calendar:gregorian_seconds_to_datetime(GregSecs),
	[UDate|_]=calendar:local_time_to_universal_time_dst(Date),
	USecs=calendar:datetime_to_gregorian_seconds(UDate),
	{{Y, M, D},{HH, MM, SS}} = Date,
	io_lib:format("~4..0b-~2..0b-~2..0bT~2..0b:~2..0b:~2..0b~s",
		[Y,M,D,HH,MM,SS,tzid(GregSecs-USecs)]).

tzid(Secs) when Secs==0 ->
	"Z";
tzid(Secs) ->
	{HH,MM,_}=calendar:seconds_to_time(abs(Secs)),
	io_lib:format("~c~2..0b:~2..0b",
		[case Secs >= 0 of false -> $-; true -> $+ end,HH,MM]).

As well as being shorter and clearer still, it doesn’t use the calendar:time_difference like the original did. That’s good because not only is that function very silly, it turns out it is marked as obsolete in the documentation. I suspect those two points are not unrelated.

Anyway, I’ll probably give the above some more rigourous testing and submit a patch. It may seem rather trivial, but actually it was a good exercise in getting to know Erlang a bit better. Half an hour of practical problem is usually worth ten of reading TFM.

YAWS continued

Thursday, August 16th, 2007

There was a suggestion in the comments that the code excerpt I showcased in my previous post was not shit at all, but rather just the way you do things in a functional programming language. By way of illustrating why it actually is shit, I present the following code that does exactly the same thing, using the same methodology:

less_shit(GregSecs) ->
	Date=calendar:gregorian_seconds_to_datetime(GregSecs),
	{{Y, Mo, D},{H, Mi, S}} = Date,
	[UDate|_] = calendar:local_time_to_universal_time_dst(Date),
	{DiffD,{DiffH,DiffMi,_}}=calendar:time_difference(UDate,Date),
	i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
        add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":"  ++
        add_zero(S) ++ tzid(DiffD,DiffH,DiffMi).

tzid(DiffD,DiffH,DiffMi) when DiffH < 12,  DiffH /= 0 ->
	"+" ++ add_zero(DiffH) ++ ":" ++ add_zero(DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH > 12,  DiffD == 0 ->
	"+" ++ add_zero(DiffH) ++ ":" ++ add_zero(DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH > 12,  DiffD /= 0, DiffMi /= 0 ->
	"-" ++ add_zero(23-DiffH) ++ ":" ++ add_zero(60-DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH > 12,  DiffD /= 0, DiffMi == 0 ->
	"-" ++ add_zero(24-DiffH) ++ ":" ++ add_zero(60-DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH == 0 -> "Z".

The point to note is that no complex expression is repeated multiple times, and nor is the actual logic of generating the timezone identifier buried within one. It’s much clearer, and much shorter.

Another point to note is that it is still shit, and I make no apologies for that, as firstly I wanted to keep the methodology the same, and secondly I am still getting to grips with Erlang.

YAWS

Thursday, August 16th, 2007

I said I would have another look at YAWS, given the apparently amazing performance. I decided to dive straight into the source, since I had more than a hunch that anything substantial written in Erlang would be an unmaintainable mass of crap. I certainly wasn’t disappointed in this case. The following excerpt is one of several chunks of code I came across that do exactly* the same thing:

(more…)

Erlang - First Impressions

Thursday, August 9th, 2007

I decided to have a brief play around with Erlang a couple of weeks ago. If you don’t know what it is already, you are unlikely to be interested, so switch off now. On the other hand if you do know what it is, I’m sure you know more than me about it, so switch off now. That leaves me writing for my future self, who is probably here either trying to refresh his goldfish-like memory or wanting a chuckle at what his former self got wrong.

(more…)

Duck Migration

Sunday, August 5th, 2007

Yesterday our ducks migrated to a pond a few miles away, not on the wing but in the back seat of a Mercedes. Only the best for our ducks. Needless to say, they took to the water like….erm… Anyway:

They settled in well and soon joined the rest of the ducks on the pond, but I suspect that despite the safety advice I gave them before we left, they will be returning home to us in due course - riddled with bullets and oven-ready. In the meantime, the young chickens are over the moon about not having to share their shed at night.