How to Protect Your Website Against Attack
Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/11/d765464148/htdocs/app765464394/wp-includes/formatting.php on line 3403
If I can't find a simple explanation, I write notes for myself. Often about things related to software engineering.
I’m about to move subscribers from the old domain host to the new one. The url remains the same, it’s just that the domain is now self-hosted.
Email subscribers will continue to receive email notifications of new posts as before, but WordPress.com followers will only see new posts in the Reader. They will not receive email updates unless they subscribe to receive those on the new site, which they can do via the Subscriptions widget at the bottom of the sidebar.
My 16-yr-old son is about to become self-employed. This is my attempt to explain why we need to keep receipts for expenses, and what impact it will have on the tax he pays.
Note that the UK tax allowance is currently £11,500 (see here), but I made it £10,000 to keep the sums simple.
There are some words and phrases whose precise meanings just won’t stick in my head. “Yak shaving” is one of them.
So I want to thank the author of this blog post, Yevgeniy Brikman, first of all for writing a great post about infrastructure, but also for providing a great visual aid to remind me what yak shaving is.
And I’m putting it here so that I can look it up, the next time I forget.
Here is a great visual example of yak shaving.
(Apologies, I would have embedded the giphy but I’m still using the web version of WordPress, which doesn’t seem to allow it. I will hopefully sort this out soonish).
I got pinged by my colleague @j_f_green this morning with the following message: “Hey Clare. Hope all is well. Was wondering if I could be cheeky and get your input on a (small) thing I’m trying to solve? I am searching for an elegant solution and I’m starting to suspect the answer may involve maths.”
…and of course I was instantly interested.
It turned out to be a relatively simple problem, depending on your point of view. If I say “GCSE-level simultaneous equations” your reaction will tell you whether that’s simple for you or not (for people not in theUK, GCSEs are the exams our pupils take when they are 16 years old).
Here is the problem: We want to discover two whole numbers (aka positive integers) that will give us the height and width of a grid in cells, given the following constraints:
width = 2 * height = aspectRatio * height
(aspectRatio will often be a decimal or a fraction, so for instance if width is half height, aspectRatio is 0.5, or if the ratio is 2:3 then aspectRatio = 2/3 = 0.66, and width = 0.66 * height)
Here is a concrete example: Let’s say we have a grid that is twice as wide as it is high, so aspectRatio = 2. Let’s also say that our capacity is 200: We want to fit at least 200 cells into this space. I’ve deliberately chosen an easy example, and the answer in this case would be a width of 20 and a height of 10:
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
Apologies if that’s making your eyes hurt. Is it making your eyes hurt? It’s making my eyes hurt. I’ll try and make a better diagram later. It’s not even got the correct aspect ratio on the page…
If you enjoy attacking maths problems, look away now. Have a go at solving it before you read on. You may come up with a better solution anyway.
One way would be a loop. Here is some code that would do the job:
var capacity = 1000;
var aspectRatio = 1000 / 800 = 1.25;int width = 0;
int height = 0;while (width * height < capacity)
{
height += 1;
width = RoundToNearestInteger(height * aspectRatio);
}Assert.AreEqual(height, 29);
Assert.AreEqual(width, 36);
Here we have a grid that has at least 1000 cells:
36 * 29 = 1044
It has roughly the correct aspect ratio:
36 / 29 = 1.24
1000 / 800 = 1.25
The problem with this is that it does not scale well. The higher the numbers, the longer the loop. But fear not – maths to the rescue.
x * y = 200andx = 2 * y = 2y
2y² = 200y² = 100y = 10x = 20 (because it’s 2y)
The first block above gives us our two simultaneous equations.
x * y = aandx = b * y
by² = a
y² = a/bandy = sqrt(a/b)
x = b * y
y >= sqrt(a/b)
height >= sqrt(capacity / aspectRatio)width = aspectRatio * height
height >= 28.28 [= sqrt(1000 / 1.25)]width = 36 [= RoundUp(1.25 * height)]So height = 29, width = 36, aspectRatio = 36 / 29 = 1.24, num cells = 29 * 36 = 1044
var heightUnrounded = SquareRoot(capacity / aspectRatio);var height = RoundUp(heightUnrounded);var width = RoundUp(heightUnrounded * aspectRatio);
These may well be the notiest notes I’ve ever published, but just in case they’re of any use to anyone… if nothing else they may whet your appetite for the new edition of Martin Fowler’s Refactoring book.
I confess I never read it first time round (not on purpose, just there are so many books in the world and so little time…), so I’m looking forward to reading it this time. It hasn’t come out yet in the UK but should be some time in the next few weeks. Mine is already on order [drums fingers impatiently].
So anyway, Martin did a webinar today on the topic of his new book, and here are my notes:
I followed this tutorial, which is very good: https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-vsc?view=aspnetcore-2.1
There were some gotchas though, so (as always) I made notes:
See also the following two posts:
Something very exciting happened this weekend – a team of amazing talented women and I entered the 25-hour Hack Manchester 2018 hackathon, and we won Best in Show.
I’ve moved the rest of this blog post over to my Medium blog.
If you have a simple .Net console app and you’d like to convert it into a .Net Core app so that you can run it from the command line on any platform (as long as you install .Net Core), here’s what to do:
See also the following post:
(I’ve learnt a lot more since I originally wrote this (for instance, how to debug your tests), so this is an updated version).
This weekend I was part of a team that took part in the annual Hack Manchester hackathon (and we won Best in Show! Yay!). We used .Net Core for our back end code, and we got stuck in the middle of the night trying to add tests to our solution. It turned out the solution was pretty simple, so I’m documenting it here.
A skeleton NUnit test:
using NUnit.Framework; namespace KiwilandRouteApplication.Tests { [TestFixture] public class DummyTests { [Test] public void DemoTest() { Assert.True(true); } } }