Insomnia and Thoughts

It’s 1:28 am. I can’t sleep. I also can’t do anything productive because I should be sleeping.

WHEEEEEE!

That being said, man, I’ve really been neglecting this blog. A guy has two kids, a wife, and a fulfilling job, and he just abandons his blog.

Honestly, writing in this blog is something I very rarely think about. What I do think about are my hobbies.

I have a Raspberry Pi Zero with an e-paper hat and battery set up on my desk that I’m trying to come up with an idea for. One idea is a display of the most recent tweet from my Twitter feed. It’s not useful, but it might be entertaining.

Another is a display of upcoming meetings. I work from home now and sometimes don’t pay attention to the time. Outlook’s reminder has a bad tendency to pop under the VM I’m working in. I’d need to look into the MS Office or Teams API to get the event info I need for that. I could even wire in flashing LEDs or a speaker to alert me.

The last idea is just a clock with weather info. I’m not a fan of that one.

These thoughts have me wondering now: Is it possible to host VS Code on the pi and remotely access it to write the code directly on it? Just point a browser at https://[ipaddess:port] and see vs code there with the pi’s local display project, ripe for editing?

The things my brain locks onto instead of sleeping. Fun ideas, but I need sleep. C’mon brain, be tired.

??= In C#

C# has had the null coalescing operator ?? For a while now. It lets you condense

if (x = null)
{
y = x;
}
else
{
y = otherThing;
}

into

y = x ?? otherThing;

It’s a great tool for both condensing code and improving readability.

I found out recently though that C# 8.0 expanded on that idea. There is a common design pattern of caching a computed value in a variable so you only have to compute it once.

private int? _Example = null;
Public int? Example
{
get
{
if (_Example == null)
{
_Example = ComputeExample();
}
return _Example;
}
}

This isn’t that bad. It works. But it’s tedious to write (especially on mobile like I am now for this post). Enter the null coalescing assignment operator.

private int? _Example = null;
Public int? Example
{
get
{
return _Example ??= ComputeExample();
}
}

I love it!