1 2 3 4 5 6 7 8 9 10 11 12 13

Blog Update

29 Jul, 2023

As this blog entered its tenth year it was desperately in need of a facelift. I had effectively stopped writing new posts because the overhead of remembering how to upload a new post each time was off-putting enough to stop me entirely.

For that reason it has been updated with new - hopefully more consistent - CSS. In addition the code and posts are deployed on each commit by GitHub actions. This means I no longer need to SSH into the server to do things by hand. This should mean the blog is editable from wherever I have git access. I also removed the terribly insecure previous method of uploading posts directly onto the server which was using a plain-text username and password.

Most importantly privacy-invading Google Analytics has been removed along with almost all JavaScript. I no longer see the need for analytics on this blog. The only remaining scripts are for code highlighting client-side as well as Disqus for commenting. Disqus is opt-in so will only load in if you click the "Load Comments" button at the bottom of each post.

Unfortunately I still rely on Google Fonts for the title font but the main body font has been updated to use the system font stack.

Finally it has been updated to .NET 7. The previous version was running .NET Core 1.1 and hadn't been updated since 2017. So much for keeping software up-to-date! The new version is on .NET 7 and the upgrade process was surprisingly easy.

While the changes between the ASP .NET versions have been a little hard to keep track of with Startup.cs being removed and everything moving into Program.cs the migration was made simple by my lazy cheat. I just created a new ASP .NET 7 application from the template in Visual Studio and moved most of the files without any changes, except to update the namespaces.

I also took the opportunity to add caching. Previously it loaded every post file from disk repeatedly just to show a single page. Now, because posts are only updated whenever the app itself is deployed and restarted, cache invalidation is trivial.

I have added the images into git too which generally causes a lot of squawking from people who use git properly (nerds), but keeping things simple should hopefully mean I fall into the pit of success. Each PNG image has been compressed further where possible.

...

Visual Studio 2022 Debugger Freezes

18 Feb, 2022

Wow, blogging with any kind of regularity is hard I kind of hard I guess. Who knew?

Anyway this was just a quick note for a problem I had recently.

I found that my Visual Studio 2022 debugger would hang, freeze or become unresponsive intermittently. Prior to the last update the process would freeze completely, however even after updating it would freeze though the IDE itself would remain responsive.

This freeze seemed to trigger more frequently when using time-travel debugging.

As usual when weird things happen the antivirus was to blame.

Excluding the process named VsDebugConsole.exe seemed to resolve at least all the debugger hangs after adding the exclusion. No doubt some more will occur but at least VS22 is usable again.

To get to exclusions on Windows 10 (old-skool) go to Windows Security -> Virus & threat protection -> Virus & threat protection settings -> Manage settings -> Exclusions -> Add or remove exclusions.

...

Attention Bubbles (Or Why Everything Happens So Much)

31 Jan, 2020

horse_ebooks tweet "Everything happens so much"

Like most side projects that devour hours of time and end up being entirely useless, this one started with a simple question:

Can recessions be predicted by increased interest in news stories about recessions?

The background behind this question -- and you'll have to forgive my complete ignorance of basically the entire field of economics -- is that recessions are a feature of capitalist economies. From what little I've read (and understood); during a boom, businesses scale up their operations to produce more and more "stuff". At a certain point the amount of "stuff" exceeds the demand for "stuff" and businesses and sectors are left holding a load of plant/equipment/employees they no longer need.

...

Bezier Curve Bounding Boxes

18 Dec, 2019

One of the challenges for generating accurate character sizes in a PDF document I encountered while building PdfPig was working out the bounding box for a cubic Bezier curve.

A cubic Bezier curve is defined by 4 points; the start, end and 2 control points.

We can number the points for use in the formulae in this post:

  • Start: P0
  • Control 1: P1
  • Control 2: P2
  • End: P3

This gives the formula for the Bezier curve:

formula from Wikipedia

...

Open and Create PNG Images in C#

18 Dec, 2019

I wanted a platform independent way to open and create PNG images in C#. BigGustave is a new library which provides a .NET Standard 2.0 compatible way of opening and creating PNG images.

To open a png image you can pass either the bytes or the stream of the image to Png.Open and then retrieve the values for pixels at any location in the image:

Png png = Png.Open(File.ReadAllBytes(@"C:\pictures\example.png"));
Pixel first = png.GetPixel(0, 0);
Console.WriteLine($"R: {first.R}, G: {first.G}, B: {first.B}");

To create a .png image in C# use the PngBuilder to define pixel values before saving to an output stream:

var builder = PngBuilder.Create(2, 2, false);

var red = new Pixel(255, 0, 0);

builder.SetPixel(red, 0, 0);
builder.SetPixel(red, 1, 1);

using (var memory = new MemoryStream())
{
    builder.Save(memory);

    return memory.ToArray();
}

BigGustave is completely open source and is available on NuGet now so if you need very basic PNG manipulation tools for platform independent .NET code why not check it out?

...
1 2 3 4 5 6 7 8 9 10 11 12 13