05 March, 2017

toad.com open mail server

So there was some controversy decades ago the past about John Gilmore's public open SMTP relay server. I wondered if it still existed.

It does!

benc@dogger:~$ telnet new.toad.com 25
Connected to new.toad.com.
Escape character is '^]'.
220 new.toad.com ESMTP Sendmail 8.12.9/8.12.9; Sun, 5 Mar 2017 08:12:44 -0800
EHLO dogger.cqx.ltd.uk
250-new.toad.com Hello dynamic-91.hawaga.org.uk [] (may be forged), pleased to meet you
250-SIZE 89000000
250 HELP
MAIL FROM:benc@hawaga.org.uk
250 2.1.0 benc@hawaga.org.uk... Sender ok
RCPT TO:benc@hawaga.org.uk
250 2.1.5 benc@hawaga.org.uk... Recipient ok
354 Enter mail, end with "." on a line by itself
Subject: test 1

250 2.0.0 v25GCiXw019546 Message accepted for delivery
221 2.0.0 new.toad.com closing connection

Received: from new.toad.com (new.toad.com [])
    by smtp-in.biscay.cqx.ltd.uk (8.14.4/8.14.4/Debian-2ubuntu2.1) with ESMTP id v25F9dpo009917
    for <benc@hawaga.org.uk>; Sun, 5 Mar 2017 15:09:40 GMT
Received: from dogger.cqx.ltd.uk (dynamic-91.hawaga.org.uk [] (may be forged))
    by new.toad.com (8.12.9/8.12.9) with ESMTP id v25F96Xw016104
    for benc@hawaga.org.uk; Sun, 5 Mar 2017 07:09:28 -0800
Date: Sun, 5 Mar 2017 07:09:06 -0800
From: benc@hawaga.org.uk
Message-Id: <201703051509.v25F96Xw016104@new.toad.com>
Subject: test 1

02 February, 2017

Why a US dollar and a Euro are roughly the same value.

A US dollar and a Euro are roughly the same value: 1 USD is about 1 EUR, very roughly (rather than, say, 1 USD = 1000 ITL = 10^25 ZWD = 60 RUR).

There is history behind that which I've not seen presented in one place. Here is my vague understanding of it.

For a few decades before the early 1970s, the Bretton Woods system fixed USD and gold (at $35 = 1oz) and many other currencies were pegged to gold/USD.

This ended in 1971, when the USD would no longer freely converted into gold by the US government, and major world currencies became free floating.

Around that time, although at little bit before, the IMF Special Drawing Right came into existence. This was defined, at the start, to equal 1 USD, which it did until the end of Bretton Woods, but it wa. The only time I've really encountered this in real life was in small print on the back of aeroplane tickets, where compensation amounts were denominated in SDRs.

The SDR was composed of a basket of different world currencies (at time of writing, USD, EUR, CNY, JPY, GBP in defined ratios) so as the USD-value of those component currencies change, so does the USD-value of 1 SDR, rather than being fixed to the initial 1 SDR = 1 USD ratio. Over time, though, the exchange rate has stayed very roughly 1:1

In Europe, they invented the European Unit of Account which was a basket of specifically European currencies. This was scaled so that at the start, 1 unit of account was equal to 1 SDR (and so inherited the property of being roughly 1 USD). Being composed of a different based from the SDR, it varied in value with respect to both the SDR and the USD.

Next came the ECU (which was invented just before I was born), another basket of European currencies which replaced the European unit of account at 1:1

Finally, along came the Euro, an actual currency with paper notes and metal coins. This replaced the ECU again at 1:1, but again was a different basket: While the ECU basket had included GBP (British pounds), DKK (Danish crowns) and GRD (Greek Drachmas), the Euro did not include those.

So the Euro has the US dollar as its great-great-grandfather through a series of basket currencies, each branched from the previous at a 1:1 ratio.

Of course, all that 1:1 substition could have gone very differently: the Zimbabwe dollar was equivalent to a Rhodesian Dollar which was equivalent to half a Rhodesian Pound (as happened with most pound decimalisations) which replaced the Rhodesia and Nyasaland pound which replaced the Southern Rhodesian Pound, equivalent to a pound sterling - but the GBP:ZWD exchange rate at the very end was something like 1:10^25.

20 December, 2016

Lua Fibre-optic Christmas Tree

In 1998, I was given a fibre optic christmas tree, lit by two coloured light bulbs powered by 2 x AA batteries. In the intervening years, the electrics broke. Finally today I got round to doing something about it.

The tree now has a bunch of neopixels where the bulbs used to be, and an ESP8266 microcontroller providing the flashing (as well as a Wifi/telnet accessible Lua command prompt).

Unfortunately, I can't see much of a different between the illumination provided by the seven pixels - I was hoping that each one would light the fibres up very differently, but that hasn't turned out to be the case. No big deal though, and maybe more optical isolation between the different LEDs and the base of the fibre bundle would help.

Interestingly, the fibres manage to project an image of the layout of the LEDs on the board (see link above) onto the wall behind the tree! and all the fibres emit a very slight blue light because there's a blue LED on the controller board.

25 November, 2016

smuggling things in a dirty bottom

The Haskell unit type, (), has just one value, also written (), right?

smuggle :: Typeable t => t -> ()
discover :: Typeable t => () -> Maybe t

x :: ()
x = smuggle "hello world"

discover x :: Just String
Just "hello world"

These allow you to inject an arbitrary (Typeable) Haskell value into unit and retrieve it later. Just don't try to inspect the resulting () value.

Rather than Haskell 98, you'll need unsafePerformIO and extensible exceptions, put together in a way that lets you hide arbitrary stuff in a thunk, and force evaluation at just the right time.

smuggle :: Typeable t => t -> ()
smuggle v = unsafePerformIO $ throw (toDyn v)

discover :: Typeable t => () -> Maybe t
discover v = either (fromDynamic) (const Nothing)
  $ unsafePerformIO
  $ try
  $ case v of () -> return ()

I could write more. But it's Friday night and I want to drink my wine.

Edit: This is now available on hackage as acme-smuggler.

24 November, 2016


When you're in a cafe

64 bytes from icmp_seq=3 ttl=59 time=26.8 ms
64 bytes from icmp_seq=4 ttl=59 time=23.9 ms
64 bytes from icmp_seq=5 ttl=59 time=26.0 ms

and then their internet dies

From icmp_seq=28 Destination Host Unreachable
From icmp_seq=29 Destination Host Unreachable
From icmp_seq=30 Destination Host Unreachable

and then there is a power cut

From icmp_seq=51 Destination Host Unreachable
From icmp_seq=52 Destination Host Unreachable
From icmp_seq=53 Destination Host Unreachable

but that reset the router

64 bytes from icmp_seq=1786 ttl=59 time=20.7 ms
64 bytes from icmp_seq=1787 ttl=59 time=24.0 ms
64 bytes from icmp_seq=1788 ttl=59 time=21.5 ms

and all is good in the world again.

10 November, 2016

a different technical writing form

My blogger draft box is full of half written posts that I haven't finished - sometimes because I'm lazy; sometimes because the draft is a pile of notes rather than something that could form a coherent post. I've tried embracing that, by dumping a lot of stuff into github at benclifford/text/wiki. This contains a bunch of rambling notes on miscellaneous topics that I have been updating as I think of stuff.

01 August, 2016

spherical camera

This week I've been playing with a Theta S spherical camera. I'm pretty impressed at what it does, given the price. Here's a gallery of images that you can scroll around.

09 March, 2016


I got a NooElec R820T Software Defined Radio.

Only got a kernel stack trace once, trying to unload the automatically loaded digital TV drivers. And I didn't have to compile anything.

About half an hour after unboxing, I was using gqrx to get a waterfall plot of various things - BBC Radio 1, Capital, PMR446, the London bus trunked radio system, GB3LW, some local business users, and some (not-decoded) ADS-B plane traffic and some classical music being played in the CB range.

I think it needs a better antenna though - I can pick up stuff ok on my Baofeng handheld that I'm not getting through this.

Also might be interesting to see if a Raspberry Pi 2 is powerful enough to run this.

02 March, 2016

Coroutines and first order functions to flash an LED on an ESP8266

The Adafruit tutorial for flashing an LED using Lua on an ESP8266 is buggy: The main loop does not yield to the underlying operating system, and instead hogs the CPU causing eventual crash - usually after about 10 seconds for me.

Here's the code reproduced from the tutorial:

    while 1 do
    gpio.write(3, gpio.HIGH)
    tmr.delay(1000000) -- waits a second, without allowing OS to run
    gpio.write(3, gpio.LOW)
    tmr.delay(1000000) -- and again

The NodeMCU people advocate using a node.js async callback style, where instead of delaying your thread, you would instead set an alarm for a callback to do the next thing. Using tmr.delay and looping a lot is strongly discouraged because it upsets the OS.

I hate that callback style of coding (for reasons).

Lua has co-routines, though, apparently because people wanted to do things like write scripts that kept yielding back to a game engine and then resuming. (See this history of Lua)

I've recently been playing with effect systems in Haskell (see blog tag extensible-effects) and realised that Lua co-routines provide enough infrastructure for (some of) this.

So I hacked up a prototype.

The "user program" looks very much like the Adafruit example:

flashDelay = 200 -- ms
function flasher()
  while 1 do
    gpio.write(3, gpio.HIGH)
    gpio.write(3, gpio.LOW)
and can be run like this;

You can also use driveCoroutineBad which uses the blocking tmr.delay instead of the asynchronous tmr.alarm, and get the same ESP-crashing behaviour as the original example.

The main difference is that calls to tmr.delay are replaced by a call to yield. In effect system language, that means the code is asking the effect handler (driveCoroutineGood or driveCoroutineBad) to perform an effect (to delay by the appropriate time) rather than performing the effect itself. How that actually happens is down to the effect handler: in the bad case, just calls tmr.delay; and in the good case, does all the wrapping up of callbacks for tmr.alarm.

This ends up looking almost identical to the code in this GitHub issue, tmr.delay() is synchronous and blocks the network stack.

On a very simple example, this is a bit overkill, but on a bigger example is probably more interesting: you can call coroutine.yield deep down inside a whole stack of functions, which becomes tangly if you're trying to build this manually as an async callback.

Other callback style stuff is hopefully amenable to this - for example, socket handling.