Clean Code, Visual Studio, Windows 11, and a bit more on ebooks

I wanted to add some more notes about the whole Kindle, EPUB, MOBI, etc. thing that I’ve been blogging about in my last few posts. As I mentioned a few posts back, I’ve been working my way through the Clean Code learning path in O’Reilly. Since I’m probably going to lose access to O’Reilly before I’m done with that, I thought I’d buy a copy of the Clean Code book, so I could finish reading it at my leisure, and to have it for later reference. With tech books, I usually like buying a DRM-free ebook directly from the publisher, when possible. In this case, I initially had some trouble finding that, but eventually figured out that it’s purchasable through the InformIT site. I bought the Robert C. Martin Clean Code Collection ebook, which contains both Clean Code and The Clean Coder. I had a discount code, so it was about $40 total.

I copied the EPUB, MOBI, and PDF files for the book to OneDrive. There are a number of ways I can read an ebook on my iPad, if it’s DRM-free and available in multiple formats. For this one, I wound up sending it from OneDrive into my Kindle app, as a MOBI file. That method still doesn’t support EPUBs. And it will copy the file up into my Kindle library, which is nice. I don’t think I’d ever copied anything into the Kindle library that way before, but it worked fine. I also copied the PDF into GoodReader. The code listings in the MOBI version look a little weird, which is a common problem with tech ebooks, so it’s nice to have the PDF handy as an alternative.

Clean Code has some example refactorings that are fairly interesting. They’re all in Java, but I thought it might be interesting to take the original Java code for one of the examples, convert it to C#, get it working, then work through some refactoring that’s similar to what Uncle Bob does in the book/videos. I found some of the code for the examples in GitHub under the Clean Code Kata user account. (I’m not sure if that’s an “official” account for Bob Martin or his organization, but either way, the code is there.)

This idea to convert some of the examples to C# and work through them was prompted in part by a desire to set up a .NET dev environment of some sort on one of my personal machines, and to maybe experiment a bit with some of the more recent .NET stuff, like .NET 6 and VS 2022. I realized that I don’t currently have any dev stuff at all set up on my desktop PC, my MacBook, or my Lenovo laptop. The MacBook is new, so I just haven’t set any dev stuff up yet. The Lenovo was bought in 2020, and I haven’t gotten much use out of it at all. And I’ve been trying to keep the desktop PC free of any heavyweight dev tools, since I just want to keep it clean for personal productivity stuff. After going back and forth on a few possible setups, I decided to install Visual Studio 2022 (Community edition) on my Lenovo laptop. I considered just installing the .NET 6 SDK and Visual Studio Code, which would have been much more lightweight, but I’m used to using the full VS product, and I can’t see a reason not to use it. And the Lenovo is the best place to install it, since I can wipe out that machine entirely and start fresh if things get too messed up. I’ve also recently upgraded that laptop to Windows 11, so this was also an opportunity to (finally) give that a try.

Of course, I’ve had other things to do this weekend too, so I’ve only gotten as far as installing Visual Studio and git, and tweaking some settings. Maybe I’ll actually do some programming next weekend. (Or maybe I’ll get distracted by something else, and the whole thing will fall by the wayside.)

MacBook issues, browsers, and bookmarks

I did a nuke & pave on my MacBook Air a few weeks ago. My main reason for doing that was to see if it would clear up an occasional problem I have where the machine crashes if I’ve been using it for more than an hour or so on battery power. Well, it crashed again yesterday, so clearly the nuke & pave didn’t cure the problem.

One other possibility I’ve considered is that maybe it’s Firefox’s fault. The crash has always happened when I’m watching a video in Firefox. That doesn’t necessarily mean much though, since watching long YouTube videos is about the only thing I’d do on the MacBook that would stress the battery for a good bit of time. Regardless, I decided to try switching my default browser on the Mac to Safari, and see how that works out.

I’ve been a big fan of Firefox since before it was Firefox. And I still like it, and use it as my default browser on both Windows and Mac. It’s been losing market share to Chrome though, and now has only a tiny sliver of the browser market. So maybe it’s time to give something else a try, at least temporarily. Safari is supposed to be very efficient in terms of battery use on the Mac, so maybe, if my underlying problem is the battery, switching to Safari will fix it.

Switching browsers, of course, means that I need to try to replicate my Firefox setup in Safari, to the extent that I can. A few of my Firefox extensions are available for Safari, but some aren’t. The two big ones are probably uBlock Origin and Privacy Badger. But there are alternatives, and I’ll play around with some of those.

Getting my Firefox bookmarks into Safari wouldn’t be difficult if I was just switching over entirely, and didn’t care about keeping them up to date in both browsers. But I want to keep using Firefox on my PC, so I really want to keep the bookmarks in sync. The best way I could find to do that was via iCloud for Windows. This article describes the process of setting it up and enabling bookmark sync between iCloud and Firefox. I went ahead and did that, and it seems to work OK. So now I have Firefox Sync keeping my bookmarks in sync between my desktop and laptop PCs, iCloud sync keeping my Safari bookmarks in sync between my iPhone, iPad, and Mac, and iCloud for Windows bridging Safari and Firefox. I think that, even if I decide to switch back to Firefox on the Mac, I may keep iCloud for Windows running, just so I can have the same bookmarks across iOS, Mac, and Windows. (I’ve always used Safari on iOS, but never really did much with bookmarks there.)

Combining my Safari/iCloud bookmarks with my Firefox bookmarks left me with quite a jumble of duplicates. I had, at some point in the distant past, used Safari as my default Mac browser, and had a bunch of very old bookmarks in there that I’d never cleaned up. And I had a bunch of out-of-date bookmarks in Firefox too, that I’d just been ignoring. So I spent some time this morning trying to clean up my bookmarks. I did that in Firefox on my PC, and hoped it would sync back to iCloud with no problems. So far, it seems to have done that.

Browser bookmarks, in general, aren’t as important as they used to be. But I’m still a weirdo who wants a nice selection of useful bookmarks organized in a sensible hierarchy. I’ll see how my current setup works over time, but I’m also considering some alternatives. On the Mac, I’ve been curious about URL Manager Pro. That might be a good home for my bookmarks. There’s no PC version, but I could just get them over to the PC via iCloud for Windows, I think.

I currently use Pinboard as a place to dump miscellaneous bookmarks, but that’s not a carefully organized collection of stuff that I can traverse easily. I’ve got over 18,000 bookmarks in there right now. So I can’t really use that for my browser bookmarks. There’s a similar service called Raindrop that seems to allow you to apply a bit more organization than Pinboard does. Specifically, it allows you to use both tags (like Pinboard) and something they call “collections”, which can be nested. So that makes it seem like I could combine my carefully organized Firefox/Safari bookmarks and my Pinboard bookmarks into one service. I’d keep the stuff I use regularly in top-level collections, and toss all of the random old Pinboard links into a “miscellaneous” collection or something like that.

Well, anyway, this is mostly just me messing around on a Sunday morning. It’s now almost noon, and I haven’t done much else with the day, other than organize bookmarks. But, hey, it’s relaxing.

replacing stuff

So I seem to have wound up replacing a bunch of stuff this week. It started with my landlord coming in to replace my air conditioning unit on Monday. They’ve needed to do that for quite a while now. That’s kind of a long story, but suffice it to say that, after around four hours of work, they managed to replace my A/C unit and thermostat. The A/C unit seems to be working fine. I can’t really say much about that, other than that it’s keeping the apartment cool and making less noise than the old one was. I’m curious to see whether the new unit has any effect on my electric bill. I can’t imagine that the old one was very efficient. I’ll look at my electric bill next month, but it’s getting into autumn now, so the bill would be going down anyway.

The thermostat is kind of interesting. The old one was a very old analog thermostat. The new one is a fairly low-end Honeywell digital thermostat. It’s programmable, but doesn’t have wifi support or any of that stuff, so you have to program it by pressing buttons on the unit itself, which is pretty annoying and time-consuming. I’ve got it running under a program, for now, but I may give up on that and go back to just nudging it up or down occasionally, like I used to do with the old thermostat.

Having the new thermostat and A/C unit has gotten me mildly interested in maybe getting a fancy thermostat with HomeKit support. But then I remind myself that I’m a single person in a one-bedroom apartment, which I almost never leave these days. So I really don’t need a smart thermostat.

The landlord was kind enough to leave the manual for the thermostat behind, so, as I normally do with these things, I wanted to put it in a folder, label the folder, and file it in my filing cabinet. I bought a Brother PT-1950 label maker in 2007, when I first got on my GTD kick, and I’ve been using it to label stuff since. But when I tried to use it to label my new “thermostat” folder, it didn’t work. I first thought that the batteries were dead, so I hopped on Amazon and ordered some new AA batteries. Then I remembered that I had an A/C adapter for the label maker, and tried that. I got an “EEPROM error”, which, according to the internet, means that I need to get the label maker serviced. Given that it’s more than ten years old, I decided to just trash it and get a new one instead. I looked at the Wirecutter reviews for label makers, but rejected their recommendations and bought a Brother P-Touch PT-D210 instead. It was only $35 from Amazon, and I was pretty sure that it used the same cartridges and A/C adapter as my old one.

It arrived today, along with the AA batteries I’d bought. The first problem was that I hadn’t noticed that this label maker uses 6 AAA batteries rather than the 6 AA batteries required for the old one. So I had to run over to ShopRite for AAA batteries. The second issue is that it uses slightly different tapes from the old one, so the half-used tape in the old one will have to get tossed. The new one came with a starter cartridge. Also, I have a spare cartridge from the old one that’s new enough to be compatible with both old & new label makers, so I have a full cartridge ready for when the starter one runs out.

So that was a long digression, all caused by wanting to print a label for a file folder. But now I have a fancy modern label maker, and I’m all set to start labeling stuff again.

Meanwhile, at work, we were notified recently that our company will no longer allow removable storage to be used on work computers. This isn’t a big problem, since I don’t normally have to use removable storage. But I do have a USB drive hooked up to my desktop that I was using for File History backups in Windows 10. (I’ve never needed to go back and pull anything from history, but I liked having it.) So now I need to give that up. Since I can’t use the drive at work anymore, I briefly though about bringing it home and using it to replace the drive I’m using for File History on my home PC. But of course it’s company property (even thought it’ll probably get recycled when I hand it back to help desk). And it’s a few years old. And a new 2 TB drive is only $60 from Amazon. So I went ahead ordered one of those yesterday. And that showed up in the mail today too.

The old drive I was using for File History at home had been acting up. It was still working, but I’d have to unplug it and plug it back in regularly to get it going. And it was almost full. It was a 640 GB drive that I bought from NewEgg in 2011, for $35. (I think it might have been refurbished.) Anyway, I guess I’ve gotten enough use out of it.

I had a second external drive hooked up to my home PC. That one was a 1 TB drive that was more than 10 years old. The only thing I had on it was a Macrium Reflect backup from 2018. I’d been wanted to do a new full image backup, with Macrium or something else, but every time I’ve tried that with my current PC, something went wrong. So I gave up on the idea at some point. I now rely on Bvckup, running daily backups to a second internal HD, which I started using in 2019, and the File History backup mentioned above. I hadn’t been having any issues with that 1 TB drive. Of course, I wasn’t actively using it, but it was recognized by Windows, and I could see the files on it. But, after I disconnected the old 640 GB drive, the 1 TB drive also stopped working. All I can think of is that I somehow shorted something out when I was removing the 640 GB drive. I spent some time troubleshooting it, but eventually gave up.

So now I just have a single 2 TB backup drive, which I haven’t hooked up yet, since it only showed up about 30 minutes ago. I’ll try to hook that up tomorrow, and hope it works.

I’ve got a box with two dead hard drives and a dead label maker in it, ready for the next Somerset County electronics recycling day, which will probably be Oct 2. And now I’m seeing other stuff around the apartment that I should probably replace. But I’m holding off, since replacing one thing seems to lead to a domino effect where I have to replace other things and buy other accessories and so on. So I guess I’ll keep using my 30-year-old toaster over for a while longer.

Ephemeral Port Exhaustion

We’ve been having some trouble with our main web server at work over the last few months. It all boils down to ephemeral port exhaustion, which sounds kind of like a post-COVID side-effect, but is actually something that can happen to a Windows server if you’re opening too many ports and then not releasing them. The post linked above contains some useful troubleshooting information regarding this problem.

I actually think the best explanation of this issue is in a 2008 TechNet article titled Port Exhaustion and You. (That link goes to the original version of the article via archive.org. Here’s a link to it’s current location at Microsoft’s site.)

The basic issue is that you can run out of ports and then anything that relies on opening a new one fails, and you just need to reboot the server. So, not the end of the world, but not good for a production server. We’ve been working around it for awhile. We had it scheduled to reboot once a week, but upped that to twice a week when it seemed like once wasn’t enough. And now it’s gotten to the point where I really think we need to find the underlying issue and correct it.

In our case, the server is running a bunch of web services under IIS. There are more than a dozen separate services, written by various programmers, at various points in time. They’re all (probably) C# programs, but they’re written under various versions of .NET Framework and .NET Core. They’re grouped into three or four app pools.

The first thing that makes sense to look at here is how the individual programs are handling outgoing network connections. Normally, in C#, you’d use HttpClient for that. I wrote a blog post in 2018 about HttpClient and included a link to this article about how to properly use HttpClient without opening a bunch of unnecessary connections. I think I’ve got all of my own code using HttpClient correctly and efficiently, though I’m not sure about everyone else’s.

It can be hard to tell what’s going on behind the scenes, though, if you need to rely on closed-source third-party libraries that also open up HTTP connections. I’ve got a few of those, and I think they’re not causing problems, but I don’t really know.

To try to monitor and track down port exhaustion issues, there are a few tools you can use. A number of the articles I’ve linked above mention “netstat -anob” or some variation of that, and I’ve found that helpful. One issue with that, if you’re running a lot of web services, is that you can’t easily see which service is causing a problem.

My big breakthrough yesterday was realizing that I could use “appcmd list wp” to get a list of the PIDs and app pool names associated with the various IIS worker processes. From that, you can tie the netstat output back to a specific app pool at least. (Of course, if you have ten web services under one app pool, then you’ve still got some more work to do.) See here for some info on appcmd.

Anyway, we still haven’t quite got our problem solved, but we’re getting closer. For now, we’ll still just need to keep an eye on it and use the old IT Crowd solution: “Have you tried turning it off and on again?”

burning data DVDs in Windows 10

I’ve never had a problem with burning data CDs or DVDs in Windows 10, as far as I can remember. I’ve generally used the built-in burning function in Windows Explorer. Well, today, I bought a bunch of comics via this Humble Bundle, downloaded all the comics in it, and then wanted to burn them to disc as a backup. I’ve done that plenty of times before, but I couldn’t get it to work today.

After going through a bunch of troubleshooting steps, I finally gave up and downloaded CDBurnerXP. That worked fine. I’m pretty sure I’ve used CDBurnerXP in the past. (I had an entry for it in my Pinboard account from 2009, so I was at least aware of it.)

I briefly considered going back to Nero, which used to be my go-to program for CD/DVD burning, as far back as 2004. But I’m not sure about Nero anymore. They do still sell their “Nero Burning ROM” program, but there doesn’t seem to be a freeware “light” version anymore, nor is there an obvious way to get a 30-day trial of their full product, so I didn’t want to spend money on that, not knowing if it would work or not.

And there’s still a Roxio product for burning CDs and DVDs, but again there doesn’t seem to be a freeware version or a trial version available.

All of which leads me into a rant about trying to find legitimate freeware/shareware Windows software these days. I’ve found that the best way to find something is to go back through my own Pinboard bookmarks and/or blog entries, and try to find something familiar that I’d used in the past. There used to be good semi-trustworthy sites for finding freeware/shareware, like Tucows (which surprisingly was still around until about a month ago.) There were a few others, but at this point, I can’t ever remember their names.

Nowadays, we’ve got the Windows Store, which should be good and trustworthy, but there’s a lot of questionable stuff in there. Is MajorGeeks.com good/trustworthy? Maybe? Their burning tools page looks pretty good. And this Best Free Software of 2020 article from PC Mag has some good stuff in it (including CDBurnerXP). I guess PC Mag is still reputable.

I get worried about downloading freeware programs that may contain malware. The Windows Store should take care of that, I guess, but it still seems like there’s a bunch of crap in the Windows Store, and a bunch of the more useful freeware utilities don’t ever make it into the store.

I wound up tweaking some security settings as part of my troubleshooting today, and I just noticed that Windows has flagged the installer for an old version of ImgBurn from 2010 as a risk. I let it delete that. (A more recent installer, from 2016, didn’t raise any alarms.) Makes me wonder if that was a false positive or not. Did I download a hacked version of ImgBurn in 2010? I guess it doesn’t matter at this point, since I wasn’t going to install a ten-year-old version of ImgBurn anyway.

Oh well. This is just another blog post from a cranky old man who wanted to spend five minutes burning a DVD backup today and wound up spending an hour or two troubleshooting and working around annoying Windows problems.

Evernote, and Apple, and other stuff

In my last post, I mentioned that I had not yet upgraded to the new version of Evernote on iOS, Windows, or Mac, nor had I been prompted to upgrade. Yesterday, the iOS client got pushed down to my iPhone. And I was prompted on my PC to upgrade to the new Windows client. (I skipped that and stuck with the old version for now.)

The iOS client is fine. I don’t have any issues with it. It looks good, and it’s no less functional than the old client, as far as I can tell. It’s not particularly fast, but neither was the old iOS client. So I went ahead and updated it on my iPad too. It works fine there. So no problems with iOS.

For Windows, I decided to upgrade it on my Lenovo laptop and play with it a bit. I’ve honestly barely used that laptop since I bought it back in June. So it seemed like a good place to try out the Windows client without having to worry about messing up my regular setup. The new client works fine, and I think I like a few things about it more than the old client, but I’d need to work with it some more to be sure. It seems to be a little slower than the old Windows client. And the font looks a little weird, but that might just be that I need to tweak the display settings on the laptop. There’s a dark mode, and I’ve found that it works better for me than the light mode. Overall, it definitely seems to be less configurable than the old version, but there’s nothing in particular that I want to change, and can’t.

On another subject: I’ve upgraded both my iPhone and iPad to iOS 14. I waited for 14.1 to come out before upgrading. I’ve had no issues on either the iPhone or iPad. I’ve messed around with widgets a bit, but I haven’t gone nuts with them. For now, I’m just leaving them on their own screen. There’s not much else in iOS 14 that I’m really interested in, but I do want to try out the “headphone accommodations” feature at some point, given that I’m partially deaf in my left ear, but have (fairly) normal hearing in my right ear. Maybe it’ll help.

Upgrading the iPhone triggered the notice to upgrade my Watch to watchOS 7. That turned out to be quite a problem. The update needed 3.1 GB of free space, and I didn’t have that much. In the past, rebooting the watch would often clear enough space to run an update, but this time I had to go as far as un-pairing and re-pairing it. That basically wipes it and leaves you with a fresh OS install, so I then had to go back and reinstall apps and redo my watch face customizations and reset all my preferred options. And it turns out that watchOS 7 doesn’t really do much for you if you have a Series 3 watch, like I do. I was hoping for at least the handwashing timer, but you need a Series 4 for that.

So that’s got me thinking about picking up a new watch. And, of course, with the iPhone 12 out, I’m a little tempted to trade in my phone too. Both my phone and watch are a little less than two years old, and I like to hold on to these things for three years minimum, if I can. So I probably shouldn’t be thinking about buying new Apple gear. But, hey, in a year when I couldn’t travel at all and haven’t had to spend hardly any money on gas or car maintenance, why not blow a few bucks on unnecessary Apple hardware?

And on one last Apple-related note: I got a lot of enjoyment out of my Apple Music subscription today. The new Bruce Springsteen album came out, and I listened to that twice. And there’s a video interview with Bruce that I watched. (Or mostly just listened to, since I was working at the time.) And a new Jeff Tweedy album came out today, so I listened to that too. And I discovered the “My New Music” mix today. Apple already knows enough about my musical taste to put together a pretty good mix, including new AC/DC, Elvis Costello, John Cale, Pixies, and Bob Mould. So I’m feeling pretty good about Apple Music right now.

Evernote changes

Evernote has been going through some changes lately. They’ve introduced new client software for iOS, Windows, and Mac. I haven’t updated to any of the new programs yet though. I assume the iOS one will get pushed down automatically at some point. For the Windows and Mac clients, I don’t think they’re pushing them out automatically, so I can probably keep using the old software until they’ve worked out the bugs in the new stuff.

The new Windows and Mac clients have gotten a lot of bad reviews, from what I’m seeing on reddit and elsewhere, so I’m a little afraid to try them. I’ve been actively using Evernote since 2014, and I’ve got a lot of notes in there. I realize that the folks complaining on reddit are probably a small subset of total Evernote users, and the new clients are probably fine, but I want to be careful.

Evernote’s CEO, Ian Small, has been doing a bunch of interviews with productivity YouTubers recently, to promote the new clients and to answer questions and concerns about Evernote’s direction. Here are links to three recent interviews:

It’s kind of interesting to see how much effort he’s putting into this, and how he’s approaching it. Evernote is big enough that he could probably be giving interviews to (for lack of a better term) more mainstream tech journalists, but he’s going with random productivity YouTubers instead. It seems like he’s trying to really reach out to the serious productivity nerds.

One thing he’s had to defend is his choice to rewrite the clients in Java Script, using Electron. That’s actually a pretty safe choice for a cross-platform app right now, but it does leave you with an app that’s probably going to be slower than an app written in, say, C# on Windows or Swift on Mac, using native libraries on each platform. But Electron apps don’t have to be slow.

With all the uncertainty around Evernote, I spent a little time recently looking at the possibility of moving to OneNote. Microsoft has an importer that you can use to make the move. I haven’t tried it, but it’s good to know that it exists. I use OneNote at work (since that’s our standard), and it’s fine, but I like Evernote a lot more.

So hopefully, they’ll keep iterating on the Windows and Mac clients, and by the time I switch over to them, they’ll be fast and reliable.

PowerShell profiles and prompts and other command-line stuff

I’ve been spending some time at work this week rearranging some stuff between my two development VMs, and I hit on a few items that I thought might be worth mentioning on this blog. I have two development VMs, one with a full install of Dynamics AX 2012 R2 on it, and another with a full install of SharePoint 2013 on it. Both are running Windows Server 2012 R2. And both have Visual Studio 2013 and 2017 installed. My AX work needs to get done on the AX VM, and any old-style SharePoint development needs to get done on the SharePoint VM.

General .NET development can be done on either VM. For reasons that made sense at the time, and aren’t worth getting into, my general .NET work has all ended up on the SharePoint VM. This is fine, but not optimal really, since the SP VM has only 8 GB of RAM, and 6 GB of that is in constant use by the SP 2013 install. That’s leaves enough for VS 2017, but just barely. The AX VM has a whopping 32 GB of RAM, and the AX install generally uses less than 10 GB. And my company is gradually moving from SP 2013 to SharePoint Online, so my need for a dedicated SharePoint VM will be going away within the next year or so (hopefully).

So it makes sense to me to move my general .NET projects from the SP VM to the AX VM. That’s mostly just a case of copying the solution folder from one VM to the other. Back when we were using TFS (with TFVC) for .NET projects, it would have been more of a pain, but with git, you can just move things around with abandon and git is fine.

All of this got me looking at my tool setups on both VMs, and trying to get some stuff that worked on the SP VM to also work on the AX VM, which led me down a number of rabbit holes. One of those rabbit holes had me looking at my PowerShell profiles, which led me to refresh my memory about how those worked and how to customize the PowerShell prompt.

The official documentation on PowerShell profiles is here, and the official doc on PowerShell prompts is here. User profile scripts are generally found in %userprofile%\Documents\WindowsPowerShell. Your main profile script would be “Microsoft.PowerShell_profile.ps1”. And you might have one for the PS prompt in VS Code as “Microsoft.VSCode_profile.ps1”. (Note that I haven’t tried using PowerShell Core yet. That’s another rabbit hole, and I’m not ready to go down that one yet…)

Anyway, on to prompts: I’ve always kind of disliked the built-in PowerShell prompt, because I’m often working in a folder that’s several levels deep, so my prompt takes up most of the width of the window. The about_prompts page linked above includes the source for the default PowerShell prompt, which is:

function prompt {
    $(if (Test-Path variable:/PSDebugContext) { '[DBG]: ' }
      else { '' }) + 'PS ' + $(Get-Location) +
        $(if ($NestedPromptLevel -ge 1) { '>>' }) + '> '
}

In the past, I’ve replaced that with a really simple prompt that just shows the current folder, with a newline after it:

function prompt {"PS $pwd `n> "}

Yesterday, I decided to write a new prompt script that kept the extra stuff from the default one, but added a couple of twists:

function prompt {
    $loc = $(Get-Location).Path.Replace($HOME,"~")
    $(if (Test-Path variable:/PSDebugContext) { '[DBG]: ' } else { '' }) + 
    $loc + 
    $(if ($NestedPromptLevel -ge 1) { '>>' }) +
    $(if ($loc.Length -gt 25) { "`nPS> " } else { " PS> " })
}

The first twist is replacing the home folder with a tilde, which is common on Linux shells. The second twist is adding a newline at the end of the prompt, but only if the length of the prompt is greater than 25 characters. So, nothing earth-shattering or amazing. Just a couple of things that make the PowerShell prompt a little more usable. (I’m pretty sure that I picked up both of these tricks from other people’s blog posts, but I can’t remember exactly where.)

Anyway, this is all stuff that I’m doing in the “normal” PowerShell prompt. I also have cmder set up, which applies a bunch of customization to both the cmd.exe and PowerShell environments. Honestly, the default prompt in cmder is fine, so none of the above would be necessary if I was only using cmder. But I’ve found that certain things were only working for me in the “normal” PowerShell prompt, so I’ve been moving away from cmder a bit. Now that I’m digging in some more, though, I think some of my issues might have just been because I had certain things set up in my normal PowerShell profile that weren’t in my cmder PowerShell profile.

Cmder is basically just a repackaging of ConEmu with some extra stuff. I don’t think I’ve ever tried ConEmu on its own, but I’m starting to think about giving that a try. That’s another rabbit hole I probably shouldn’t go down right now though.

I’d love to be able to run Windows Terminal on my dev VMs, but that’s only for Windows 10. (It might be possible to get it running on Windows Server 2012 R2, but I haven’t come across an easy way to do that.) Scott Hanselman has blogged about how to get a really fancy prompt set up in Windows Terminal.

And at this point, I’ve probably spent more time messing with my PowerShell environment than I should have and I should just settle in and do some work.

moving and resizing windows in AutoHotKey

One of the minor little issues I’ve had since this whole “work from home” thing started is that I frequently need to switch back and forth between using my laptop on its own vs. remoting into it from my desktop PC. I always need to be connected to our work VPN, and we’re not allowed to install the VPN client on personal PCs. And I don’t have an easy way to connect my personal monitor, mouse, and keyboard to the laptop. (Yes, I know there are a bunch of reasonably easy ways to do that. I just haven’t made the effort.) So I spend most of the day remoted in to the laptop via RDP from my desktop PC. But I disconnect and use the laptop directly whenever I need to be in a meeting, so I can use the camera and microphone. (And, yes, there’s probably a way for me to use the camera and mic while remoted in, but I haven’t bothered to try figuring that out either.)

Anyway, the issue with all that is that the change in resolution between the laptop screen and my desktop monitor confuses things, so my window sizes and positions are generally all screwed up when I do that. So I wanted to write a little AutoHotKey script to automatically move and resize the windows for my most commonly-used programs. (In my case: Outlook, OneNote, and Firefox. I do my actual development work via RDP into a VM, not on my “real” computer, so it’s just the productivity stuff running on the laptop.)

Of course, given the way these things tend to go, I just lived with it until June, when I finally got around to writing the script. And, again, of course, I found issues with the script, but didn’t bother correcting them until… today. So here’s a script that looks at the current monitor’s resolution, then moves and resizes Outlook, OneNote, and Firefox so they’re tiled and just the right size for my preferences.

SysGet, Mon1, Monitor
;MsgBox, screen dimensions: %Mon1Right% x %Mon1Bottom%

X := 70
Y := 32
Width := Mon1Right - 240
Height := Mon1Bottom - 150
;MsgBox, X=%X%, Y=%Y%, Width=%Width%, Height=%Height%

WinRestore, ahk_exe OUTLOOK.EXE
WinMove, ahk_exe OUTLOOK.EXE,, X, Y, Width, Height
WinRestore, ahk_exe firefox.exe
WinMove, ahk_exe firefox.exe,, X*2, Y*2, Width, Height
WinRestore, ahk_exe ONENOTE.EXE
WinMove, ahk_exe ONENOTE.EXE,, X*3, Y*3, Width, Height

Nothing fancy, but it does what I need, and I thought it might be useful to post it here. It’s using the SysGet command to get the screen dimensions, and the WinMove command to move the windows.

I also considered using PowerShell with WASP for this, but I’m more familiar with AHK.

new Lenovo laptop

The new laptop that I ordered on Sunday showed up today. It’s a Lenovo Flex 5, from Costco. I don’t have much to say about it yet. It’s about what I expected. It seems to be pretty solid, but it’s definitely from Lenovo’s consumer side rather than their business side. It’s got a touchscreen, and it can be folded all the way back so it can be used as a tablet. It didn’t come with a pen, but it appears to support pen input. I don’t know much about Windows 10’s pen support, but I might look into it, just out of curiosity.

The keyboard is okay, but not great. And the layout is sensible, but of course it’s at least slightly different from my other two current laptops (my personal MacBook Air and my work HP laptop), so I’m going to be stumbling on key locations, but that’s life. The camera works, but apparently can’t be used with Windows Hello. (That’s fine. I don’t really need that.) It’s also got a fingerprint reader that I haven’t tried to set up yet.

The laptop didn’t have too much bloatware on it. During setup, Lenovo gives you the option to install a few things that you really don’t need, so I appreciated the opportunity to decline those. I did have to uninstall two separate McAfee products though. I got a few essentials installed on it today (Evernote, 1Password, Firefox, Notepad++, and a few other things). And I got it updated to Windows 10 Pro (from Home). I’ll probably install some dev tools on it tomorrow and/or over the weekend. And maybe Steam too, so I can play some games.

I have a couple of other topics I wanted to blog about too, but they’re totally unrelated to this, so I may write them up separately later or over the weekend.