2020-03-29

Rules

Before anyone has a go about looking for loopholes, please just stay at home. If you have to go out, keep away from people, try not to touch your face, wash your hands (take sanitiser with you even). Stay safe!

However, when the new rules actually came out (here), and I mean for England, as, confusingly, other UK countries are not quite the same, I did wonder how the police were supposed to enforce them at all.

For example, a gathering of more than 2 people is prohibited, unless from same household. How to you prove you are from the same household, or, more importantly in an "innocent until proven guilty culture" how do the police prove you are not? You don't have to carry ID.

But I assumed some sense. E.g. a couple with a child going for a walk are probably OK, but a group of 20 teenagers is probably not.

Sadly the police are not being sensible, even publishing drone footage of a couple walking way apart from anyone else, and suggesting somehow that was not allowed. Worrying times.

But then you get to some of the more complicated rules. In this case I am not so much pointing out loopholes, as highlighting some rather crazy drafting of the law.

Funerals

A gathering for a funeral is allowed. You can leave your home to attend a funeral, but only of a member of your household, a close family member, or a friend. However, you can only go to a fiend's funeral if there is not a member of the same household or close family attending. But it seems like if none of your household or close family attending the friends funeral rather than close family or same household as the friend, which is rather confusing. It looks like if two people in the same family or household know someone as a friend, only one of them can go to the funeral. This is almost the reverse of the gatherings rule where people have to be the same household - at a funeral they can't be the same household, if the deceased is a friend, but can if the decided is their family. Arrrg! How do you police that and why is that the rule? It makes no sense!

It would have been far simpler to say funerals max 25 people or something simple and enforceable, but no, they have created convoluted rules.

But wait, it is not that simple. The convoluted rules only relate to leaving your home. It is the valid excuse to leave if to attend a funeral. If you leave your home to, say, exercise, you can then go to a funeral (an allowed gathering).

So it seems the only safe way to go to a friend's funeral is to wear a jogging outfit.

I can only hope none of us have to attend many funerals though - so please stay home and stay safe.

2020-03-24

Business as usual, or is it?

Obviously, to slow the spread of COVID-19 cases and reduce burden on NHS, we need people to stop interacting as much.

TLDR; governments have given five different messages about going to work, from yes you can, to only key workers, shutting down the economy almost entirely, with no clear message. It is causing confusion and will cost businesses and livelihoods.

The message from the government last night seemed clear...

Don't go out, but you can get food, medicine, and importantly you CAN GO TO WORK. Ideally, you work from home if you can, but all that was being shut down is the face to face shops and places where people gather and spread the virus a lot with other random people. Indeed, stopping all contact probably does not help as the spread just comes back as soon as you relax the lockdown - this is all about statistics - reduce contact enough to allow the NHS to cope.

It was, otherwise, for all those offices and factories and businesses that keep the economy going - business as usual (working from home if you can).

Now, assuming this is enough to slow the virus, that is great, well done UK government.

So, yes, please follow advice, stay at home, let's slow this spread enough for the NHS to still work.

My issue, however, is the horrible mixed messages from the government, which is really causing a lot of confusion.

First the message was, you can go to work, but try and work from home where possible.

Then, No10 twitter tweeted (image below) that you can go to work (if you're a key worker).

Now that is a massively different message. That is shutting down the whole UK economy in one go over night with no notice. That is HUGE!

They deleted the tweet, and changed so you can go to work (but work from home if possible) as per the speech. OK, good.

This was however a massive mis-direction and confusion by a tweet that was up for a while last night.

But it gets worse, a document about the lock down (here) says, in bold and underlined: "Non-essential businesses and premises must now shut!" We think this is meant to be a heading, and wording like "Non-essential businesses and premises that must now shut:-" or some such, but that is not what it says.

Again, confusing and mixed messages.

But now they are SMSing everyone with a link to gov.uk/coronavirus which says not to go outside except for "essential work", which is yet another unclear term, and again suggests a complete UK economic shutdown.

So what the hell is the message meant to be - is this business as usual apart from shops, or what?
Why the hell are the government not giving a CLEAR MESSAGE?

P.S. Obviously offices and factories have some duty of care, so things like people being able to keep apart and hand sanitisers and so on are an important step as well.

P.P.S. as per final image below, they have now changed the web site to say "work (where this absolutely cannot be done from home)". This is a total shambles!

P.P.P.S. the BBC have yet another, subtly different wording: Travelling to and from work, but only if it is "absolutely necessary", which is not clear either, is it necessary for you to still be paid, or is it "necessary work", i.e. key worker stuff?

P.P.P.P.S. as of this morning (25th) they have finally changed the PDF guidance document. That is three separate bits of government information that have changed now, having initially given misleading or wrong information.

Here are the messages:-









2020-03-14

Pi day

As it is Pi day (14th March) I thought I would say something obvious, but slightly mind blowing about another irrational number.

When you square a decimal number, you always end up with twice as many significant digits, or one fewer. e.g. 214² = 45796 (3 digits times 2 is 6, but in this case one less, 5), 56² = 3136 (2 digits times 2 is 4). If you think about it, it is obvious. Basically, for the last digit you multiply out not to count as a significant digit, it would have to be 0. You can do that with 2*5, but not by squaring any final significant digit.

But √2 is irrational. It goes on forever. It starts 1.41421356237 (12 significant digits), which squared is be 1.9999999999912458800169 (23 significant digits, i.e. 12*2-1).

Obviously the more digits, the closer... even lots, such as 1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206057147010955997160597027453459686201472851741864088919860955232923048430871432145083976260362799525140798968725339654633180882964062061525835239505474575028775996172983557522033753185701135437460340849884716038689997069900481503054402779031645424782306849293691862158057846311159666871301301561856898723723528850926486124949771542183342042856860601468247207714358548741556570696776537202264854470158588016207584749226572260020855844665214583988939443709265918003113882464681570826301005948587040031864803421948972782906410450726368813137398552561173220402450912277002269411275736272804957381089675040183698683684507257993647290607629969413804756548237289971803268024744206292691248590521810044598421505911202494413417285314781058036033710773091828693147101711116839165817268894197587165821521282295184884720896946338628915628827659526351405422676532396946175112916024087155101351504 squared, is 1.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999843358064061778389918448031979379487768885015043845659822004916377513166730291211571068952082602447585053372271803775212141335211046806468017544012173246168673653215429898752600809076945040478226149804752092795249913294211896685919489781038912339790863836308797672158570101054709837854108990150947671626758096902141232172374611365869462539815599093474631680641002315522198827855254655681178183773171267162025505081207619119154315015019593781997539423459450924437955866358803983089345879502011206070716091422845617882605404958297112110314310433923158845197889301909351312924983769999151087074570462040601631719823168853951704021687236598419124498942731362178121174457523357788222619729955636686231081657732082989686914502778260949270241394967997279088545806588326980598466346571508275959469245048169832037947129583450529101421217940987273080154757322849492641724996747550397932241142493214043106291202086235967891808498928787226259087932847850782010982642427061227177199617553123685346155963957806300620208169830364794225870383219224922644130340677633853727891782934367363062016

Yes, lots of 9's after that 1. but it just gets more complex.

What must blow your mind is that ultimately, to infinite digits, the answer does actually cancel out and actually end up as exactly 2.

How?!?!


2020-03-09

Backwards compatibility!

Arrrrrrrrg!

As I said, I have made a nice new decimal maths library and am using it in one of my bits of code.

It was a simple update. The original code evaluated a simple sum and provided an answer. It was a tad quick and cheerful (a bit of a bodge) but worked well enough until recently. The new code does the same but using my new library.

What could go wrong - it was a function to evaluate a text decimal sum, simple as that. How hard could it be?

The original function just added and subtracted. It worked out how many decimal places were in play and did integer maths to that precision and printed result to that many places. I said it was a bodge.

This meant, as a fluke of the way it worked, 1.00+2 would be 3.00. I.e. the number of places in the output was dependant on the max number of places of the arguments. This was never a documented feature, but guess what, people were assuming it would work like that. This is in spite of output formatting for money to two places which is what I was using in my stuff.

Then we get the fact the old code allowed blanks for operands and treated as 0. Again, a fluke of the original code and not a documented feature, but once again, they were relying on it.

It is infuriating having to make special cases in code to reproduce old and totally undocumented side effects in some function just to keep users happy! I suspect that even if the manual had said "You cannot assume a specific number of decimal places in the output" and "Behaviour for an input that is not a well formed numeric expression is undefined and cannot be relied on" it would not be any different. Users are like that!

I am waiting for the next thing, but I have a feeling it is a side effect of the total lack of error handling and syntax checking in the earlier bodged code. I might end up refusing to fix what happens when total garbage is thrown at the function and insist they fix their use cases. We'll see how bad it is.

Arrrrrrrrrrrrg!

No comment

It seems blogger have broken something - no matter ho much I clear cookies and so on, I am not able to comment on my own blog!

It used to be that it understood it was me, allowed me to edit posts directly from my blog, and comment, and reply to comments as me.

Sadly, it is not doing that - I have to go in to blogger and from there I can make new posts and edit posts, but even then I am unable to actually comment or reply.

So if you are wondering why I have not replied lately, blame blogger.

Grr.

P.S. Apparently it is not just me! Thanks for confirming, Neil.



P.P.S. looks like using incognito actually asks me for my login, and then oddly the main browser window knows who I am, WTF? So, err, fixed now.

P.P.P.S. and magically, a little later, it forgets who I am again and won't ask me for a login. Grrr

2020-03-08

Big number maths

One of my first C programmes ever, at uni, was a calculator. I had done a lot of code in BASIC, Z80, 6502 and other languages before, but C I learned at uni.

It was a strange exercise for me as I was teamed with someone else, and basically gave up on him. To me a calculator, i.e. something that could parse 1+2*3 and get 7, and understand brackets, was inherently simple. The code was a couple of pages at most and I had added all sorts of extras over and above the basic +, -, *, / binary operators. It handle brackets and operator precedence, and even had a table of operators to allow easy expansion. My "partner" made code that was dozens of pages and every test that involved extra brackets or some unexpected sequence broke it and he had two add extra code for edge cases. Oddly I once encountered a compiler that must have been written in such a way as adding extra brackets, e.g. 1+(2*3), actually broke it and made wrong code. Scary that stuff like exists.

My code has a simple loop to process: prefixes or "("s, operand, postfixes or ")"s, operator, in a loop, ending after last operand. It stacked operands, and operators (after processing the stack for any higher operators before adding), and that was it. It allowed unary pre and post operators, and binary operators. Simple and easy to understand, IMHO.

Of course, it used the normal C code to parse and output numbers, storing internally as floats (I think).

However, having played with mechanical calculators, one of the things I have meant to code one day and had not got around to for over 30 years, is a decimal calculator library... That is until this weekend.

Basically, one tool I have written, and my friends use a lot, includes an "eval" function to evaluate a simple sum for them. It is used in loads of places (as it embeds maths in a back end for a web page). It used integer (long long) types (64 bit) and shifted by number of decimal places it saw, giving it around 18 significant digits. Sadly it broke if you went over that (my bad) and they had some silly case of some numbers plus a fraction which had rather too many decimal places. So they asked me to fix.

A simple fix was limit the size, and then limit size and apply bankers rounding at the limit.

But I decided this may be the time to finally do that decimal maths code. I googled, and there are a few decimal libraries. There are also some arbitrary precision binary libraries. To my surprise the latest GCC has decimal types, where data is stored and processed in decimal. I can only assume we have decimal maths in some processors even, these days. This is good for accounting where the rounding errors you can get are bad (essentially binary does not have a way to represent 0.1 or 0.01 without recurring digits). Sadly GCC may have it, but clib does not yet (scanf and printf), but will some time, and I can see that being useful. Even so, _Decimal128 does have limits on number of digits. There are libraries in other languages, but I wanted something for C.

So I made a C string decimal library, and put it here on GitHub for all to use.

It is a library and command line, and includes functions to add, subtract, multiple, divide, and compare, as well as a simple evaluation function that parses basic sums, just like my uni project calculator.

The key thing is that it works on C text strings for numbers. A simple sum (I learned at school, and now out of date) was 366.2564*86164.091=31558149.7789324. It was numbers from an encyclopaedia in the library. I remember because I had to do the maths manually as no calculator I had would do it to full precision. Even google calculator truncates it a bit. That was my first test, and it worked. Yes, I also learned π to 50 places (and now only remember 25).

So, for add, subtract, and multiple, it is simple to ensure you have as many digits as needed. Sadly division can go on for ever, so I had to include a limit of decimal places, and a rounding rule, and remainder option.

I included rounding on limit on division, and also a separate simple rounding function - obviously actually applied at whatever digit you set. Default is banker's rounding :-

  • Round towards 0 (i.e. -3.9 rounds to -3)
  • Round away from 0 (i.e. -3.9 rounds to -4)
  • Round towards -ve (i.e. -3.9 rounds to -4, 4.2 rounds to 4)
  • Round towards +ve (i.e -3.9 rounds to -3, 4.2 rounds to 5)
  • Simple rounding (i.e 2.4 rounds to 2, 2.5 rounds to 3)
  • Banker's rounding (i.e. 2.4 rounds to 2, 2.5 rounds to 2, 2.6 rounds to 3, 3.5 rounds to 4)
I went further though, and made the calculator work on rational numbers, that means all of the maths is done with numerator and denominator, and only finally at the end does the division get done and rounding applied. This means that 1000/7*7 is 1000, unlike bc which makes it 994. minor optimisations for adding/subtracting with same denominator, and anything with denominator of 1 or a power of 10, making it simpler. For anything without division the maths does not even need a final divide.

I had a few silly bugs, one that fooled me is that zero is a special case, which I store as a magnitude of 0 and no digits, which is fine, but comparing numbers I started by comparing magnitude before comparing digits, so 0 looked like a bigger number than 0.1 as 0 was 0*10^0 and 0.1 was 1^10-1 and magnitude 0 is greater than magnitude -1. I had to add checks for comparison with 0.

However, overall, I am quite chuffed. Heck, I even asked it to work out 1e1000000000+1 and it just worked, that is a billion significant digits!

This is pure coding fun though. But may be useful - feel free to use it.

P.S. Someone asked about Banker's rounding, and I was sure I had blogged once, but cannot find it. Unlike that which I was taught at school, and every Casio (and other) calculator I had, rounding is not as simple as you think. I used to assume that a residual of exactly 0.5, or above, rounded up, and below 0.5 was down. That is what my calculator did. However, this creates a bias. Ideally you want to round an exact 0.5 residual down half the time and up half the time to remove bias. This could be random, but that is bad as you get results which are not reproducible. One simple way, bankers rounding, is to round 0.5 residual to nearest even number. Hence 0.5 rounds to 0, 1.5 rounds to 2, 2.5 rounds to 2, 3.5 rounds to 4, and so on.

2020-02-23

Internet in a box

I have finished my cruise now, which was mostly holiday, but also some work. I did some training for my mates (mainly in C coding) and we did various coding as well (there were a few sea days). But now I am back I am making up the next version of my "internet in a box" that I take on cruises like this. I'm doing it now whilst I remember the last cruise in detail, even though my next cruise is some way off.


OK, that is not it - we have one of those, and it would be really cool if I could fit the bits in that box, but at present is is a tad larger... More like this...


So, what's in the box?
  • FireBrick FB2900
  • Aruba 501
  • 2x Aruba AP-303H
  • 3x PoE injectors
  • 1x 4 way power strip
  • Magic tape to hold it all in place
This is obviously somewhat overkill, so worth some explanation...

FireBrick FB2900

The FireBrick is a "swiss army knife" of network contraptions. It does a lot.

When you are trying to use internet on a ship you have a challenging, even hostile, environment. There are blocked ports and protocols, 700ms round trip latency (or randomly much more), packet loss at various levels, strange MTU issues, and seriously messing with TCP packets (acceleration). This can all change on the fly as you travel (the Panama trip was especially complicated).

To be clear, this is not stealing internet service - it is expensive and we pay for the premium, unlimited, steaming package for multiple devices. This does allow connection of devices that do not have WiFi or have a browser.

Whenever I take a FireBrick on a cruise we find new ways to improve it. This can be changes to handle high latency, or new features to handle some of the limitations. Even simple higher level protocols can struggle with the very high latency and low level packet loss. A lot of new features are the result of testing in this harsh environment and have benefitted the FireBrick code. Not sure I can expense my cruises as R&D just yet though, shame.

So, this alone, is one of the reasons for the crazy set up. The FireBrick can do various VPNs, UDP over faked TCP, TCP relaying, all sorts.

The main objective is to connect to the ship internet (WiFi) and provide internet to laptop or apple TV. For the apple TV to work in any expected way without regional blocks, it needs a working UK IP address in some way, and the FireBrick can do that.

The FireBrick can also monitor the connection in various ways and fall back, even to simple NAT over the ship's WiFi as last resort, and report status on an LED to make it obvious. If ever I fit this in one of those black boxes, the LED will not just blink red :-)

Aruba 501

This is a rather nice WiFi client. It connects to the WiFi and can do MAC cloning, where it will associate using the same MAC address the FireBrick is using. We found that the WiFi on ship filters other MAC addresses, and even locks down the connection after a little while if it sees more than one MAC. We were changing MACs every day until we managed to lock it down to no see any others.

Aruba AP-303H

Having connected to the Internet, and set up a VPN, we then provide internet over WiFi. It can be done with cables, but WiFi is fine and not as messy or such a trip hazzard. Previously I took a larger ceiling mount AP, but that gets hot, especially if not ceiling mounted. So this time I have smaller, and lower power, AP-303H units. I also have two, one facing each way, so the box can go in the corridor. Ships have big metal walls which make WiFi tricky. Even so, I am taking some 10m ethernet cables to allow me to place the APs to cover the whole cabin if necessary.

We actually had to set a hidden SSID, as we found that in at least one port we were seeing de-auth attacks. Interestingly this was not happening once we changed to hidden SSID. Even with the metal walls, we often see people running personal hotspots when in port, so it may be an attempt to stop that (AFAIK not legal to de-auth people like that, but who knows on a ship).

Update: Having two APs powered by PoE means I have more options - running a cable to place one, or both, APs, in more suitable locations in the cabin if they don't work in the box.

PoE injectors

This is another change from previous cruise - the last couple of times I took a nice 8 port Aruba PoE switch, which is quite big and has a big chunky power supply. This time I have three small PoE injectors which take a lot less space overall. There are some multiple port in-line PoE injectors which may be a good alternative to consider, but even with just one such unit I still need a power strip to power it and the FireBrick.

The AP-303H includes a switch, so if I need more Ethernet ports, they can provide them, so the bigger switch was not needed.

Power strip

The three PoE injectors and FireBrick mean a 4 way power strip - though I am considering making a lead with daisy chained C13 plugs and a C8 all on one lead perhaps. However, the 4 way strip fits fine. One option may be an IEC socket in the side of the Peli case so it can be closed. It looks like the whole lot is not generating enough heat for that to be an issue, but something to test.

Update: One idea is to use a 4 way IEC distribution board instead, which may well take less space.

Spare space

The whole box, even with all those bits taped in to place, has a lot of space. In fact I can pack my laptop, charger, mouse, mat, Apple TV, spare cables, phone charger, and so on, all in the one case. This means all of the tech in one small Peli case which then just sits in the corridor to provide "internet in a box".

Why?

Update: This allows me to bypass much of the hostile environment, and have clean Internet access on my own IP addresses. It even allows me to have a standard VoIP phone on the table in the cabin if I want. It allows devices that could not connect to ship's WiFi on their own (I had some of my IoT stuff on it). It is not trying to be the cheapest, or even the smallest (though I am trying to make it smaller). It mainly allows testing and development of the FireBrick in such an environment, and it is fun (for me), even if it is overkill.

Update

A few more pictures. I decided to go for an IEC distribution panel inside, and fit connectors to the case itself, and add a 3G/4G dongle.






P.P.S. Using V2.0.0.1-Aruba501-B0013 on the Aruba 501 was Crashy McCrashFace, but V1.0.1.3-HP501-B0012 seems to be stable.

2020-02-20

RevK 2.0

So, I think I have svn reverted to 1.0, or maybe 0.9 now, as I have a cold, but my mates were talking of RevK 2.0 over the last month.

Largely because I let them talk me in to :-

  • Going out in the sunshine - in tropical climates
  • Sitting on a sunny breach
  • Going to a Jazz bar
  • A tour of a warship
  • A tour of an aircraft carrier
  • Swimming in the sea
  • Swimming with dolphins
  • Snorkelling (well, I tried, but kept hyperventilating)
  • Parasailing (felt sick, life jacket was too tight)
  • Boat trip to see crocodiles (they were mostly tiny)
  • Going on a submarine (albeit docked)
  • Several open top bus tours (which I do not normally go near)
  • A walking tour in a hot city (Cartagena, Colombia)
  • Taking a picture of an Aruba access point, in Aruba
  • Oh, and wearing a Panama hat, in Panama
So over all, a fun trip! I did not do the jet skiing, just took pictures.

Here is a small selection of the pictures...