Laundry Basket Bias

You may have noticed this blog have been very quiet for the last few years. This is because last in 2018 we had beatiful twin girls born in our family. And this made total count of kids 3. This leaves me with very little time for any hobbies, including blogging and open-source development. All that time is now replaced with time with kids or for kids (cleaning).

With this amount of little humans in the house, volume of laundry increased 5-fold. When it was only myself and my wife, we maybe had a laundry load washed every 4-5 days. These days I’m doing a load of washing every day, sometimes even two.

And being a developer I was looking for patterns and ways to optimise this work (this chore somehow landed mostly on my shoulders). One of the observations I’ve made:

Clothes items tend to be used more often then others if they got into a laundry basket.

I call this Laundry Basket Bias.

The mechanism is as following: a T-shirt gets into a laundry basket, gets washed, gets dried, ends up in the basket for sorting. When I’m getting dressed, usually this is a rush (because that’s the way with three kids), I tend to grab something from top of the basket with clean clothes while running downstairs to stop the 3-year-old from hitting his 1y.o. sister.

So that T-shirt I grabbed – I wear all day, kids wipe their dirty hands on it, etc., I wash it at the end of the day. Next morning it is usually back to the dry pile, usually it ends up on top of the pile, and usually I grab it while running downstairs to sort out another drama between little people.

Same happens to socks, jeans, underwear, etc. So some of the itmes get a lot more use than others because they ended up on top of the clean clothes pile. This is a Laundry Basket Bias.

mstsc.exe vs HD screen

This post is mostly a copy of this post. I don’t want to steal a thunder from Chris – all his idea. So here I’ll just copy the commands to execute – mostly for my own future reference. And for the details go read that post

cd %systemroot%\system32
copy mstsc.exe mstsc2.exe
cd %systemroot%\system32\en-us\
copy mstsc.exe.mui mstsc2.exe.mui
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /t REG_SZ /v "C:\Windows\System32\mstsc2.exe" /d "~ DPIUNAWARE" /f

Windows Terminal

I’ve been reinstalling all my machines a few times in the last month (because reasons). These times are always a good reason to review your tools, change and upgrade.

Recently I’ve been hearing about Windows Terminal and decided to give it a go. Prior to that I’ve been using ConEmu, but I never been a fan of it for some reason and lately I’ve noticed it was becoming slower and slower to load. Also amount of configurable options always gave me a slight anxiety as I could never find options I’m after.

Turns out Windows Terminal is a pretty good implementation from Microsoft – it does the basics that I wanted: multiple tabs and sane Copy-Paste shortcuts. As a bonus you can change colour schemes. There is no option to do transparency (there is acrylicOpacity that is similar, but gets disabled by Windows when window looses focus, so beats the purpose). Otherwise I did not need to install ConEmu.

As a bonus, to start Windows Terminal from Run As window – all you need is wt command:

Also I love Matrix colour scheme with black background and lime-green text. Here are quick links to documentation on how to use settings and what options are available.
So here is my configuration for my own future installs and for you to get ideas from:

Using private NuGet feed with dotnet publish

In Azure DevOps you can have your own private NuGet feed and I’m using that extensively. But sometimes authentication there is a pain.

This time I run into authentication issue while executing dotnet publish for a probject that used that private feed:

Unable to load the service index for source https://mycompany.pkgs.visualstudio.com/DefaultCollection/_packaging/MyFeed/nuget/v3/index.json. [D:\a\1\s\src\MyProject.csproj]
error :   Response status code does not indicate success: 401 (Unauthorized). [D:\a\1\s\src\MyProject.csproj]

The reason for that is that dotnet publish does restore by itself, even though all the packages have been restored previously via dotnet restore.

The solution for this is to do the obvious thing: don’t restore on publish vis --no-restore.

But that gave me more errors:

error NETSDK1047: Assets file 'D:\a\1\s\src\MyProject\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.0/win-x64'. Ensure that restore has run and that you have included 'netcoreapp2.0' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers. 

Solution for that was to add <RuntimeIdentifier>win-x64</RuntimeIdentifier> in my csproj file.

The overall process goes like this:

dotnet restore MyProject.csproj --configfile D:\a\1\Nuget\tempNuGet_2089.config --verbosity Detailed

Where tempNuget file is configured by Azure DevOps and contains the credentials for the private feed.

dotnet build MyProject.csproj
dotnet publish MyProject.csproj --configuration Release --output D:\a\1\a\MyProject -r win-x64 --no-restore

And my csproj file looks like this:

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>netcoreapp2.0</TargetFramework>
  <RuntimeIdentifier>win-x64</RuntimeIdentifier>
  <StartupObject>MyProject.Program</StartupObject>
</PropertyGroup>

Keyboard Shortcuts for Git in Visual Studio

For my day-to-day tasks, I use Visual Studio almost 80% of my working time. About 99% of my work I commit to git and push to server. This is a lot of commits per day. And Git interface in Visual Studio is very clicky, very mousy. So I spent some time trying to improve this by researchign and adding shortcuts. Here is what I got for the most used actions:

In Keyboard configurationof VS assign the following actions to the following commands

  • Team.Git.GoToGitChanges => Ctrl+G, C (Global) => Opens Team Explorer and switches to Changes view.
  • Team.Git.CommitAndPush => Ctrl+G, P (Team Explorer) => Once the commit message is done – you can slam that to get commited and pushed to the server.
  • Team.Git.Commit => Alt+Enter (Team Explorer) => This mimmicks shortcuts in VSCode

I’m playing a bit more with these and will report here if I come up with any improvements, but so far this makes it all slightly faster.

Also for keyboard shortcuts, namespaces Team.Git.GoTo* is worth exploring for navigation options. And Team.Git.* is just worth looking for options that you do with Git in Visual Studio.

Decotrator Pattern Kata

I was explaining Decorator pattern to a colleague of mine and came up with a little coding exercise, code kata to practice.

Here is the task:

Get a class that always outputs “Hello world”. Surround that string with round brackets and then with square brackets, then with round brackets again. You should have 2 decorators. Each decorator can only add a single set of brackets. Output should be “([(Hello world)])”. Also it should be very easy to change order of brackets or add more brackets.

Here is my stub at it.

Count of rows per table in SQL Server

A lot of times I have to study a new database and count of rows per table has been a great source of info. There are many ways to get number of rows per table, but I’m sick of looking it up every time. So here goes one I prefer:

SELECT 
    SCHEMA_NAME(t.schema_id) AS SchemaName,
    t.NAME AS TableName,
    Sum(p.[Rows]) as [RowCount],
    'select top 1000 * from ['+SCHEMA_NAME(t.schema_id) +'].['+t.name+']'
FROM sys.tables t 
    INNER JOIN sys.partitions p ON t.[object_id] = p.[object_id]
WHERE 
    t.NAME NOT LIKE 'dt%' 
GROUP BY 
    t.NAME,t.schema_id
ORDER BY 
    Sum(p.[Rows]) desc

Here is a discussion with more ways to do the same thing.

CloudException: Please register the subscription with Microsoft.Insights

While trying to connect Azure Automation and log Analytics I came across this error:

CloudException: Please register the subscription {your sub ID} with Microsoft.Insights

Message is clear, but how do I do this?? Took me a while to figure out.

  1. In your Azure portal head to your Subscriptions, pick the required subscription
  2. Inside of a subscription pick “Resource providers” – you’ll be presented with a list of providers.
  3. From the list of providers pick microsoft.insights and click Register.
  4. This fixed my problem

Protect your your Azure Resources from accidental deletion

Last week I’ve messed up a big time. I was doing Azure Storage Account migrations via a PowerShell script, part of that script was deletion of old resource group. That group was meant to be empty every time because I was moving resources out of it.

At one point script threw exception and last storage account was not moved out of the resource group, but last line of the script was to delete that resource group. And it deleted the storage account. OOOOPSSS!

We had backups of data, but that accident made us think twice about our practices. So as part of a response to that accident we decided to use RM locks on all resources.

Azure Resource Management allows to lock subscription, resource group or individual resource to prevent users from accidentally deleting critical resources. Locks can be CanNotDelete or ReadOnly. Read more about locks in official documentation. If you put a subscription lock it covers all resources and groups within this subscription, but for our purposes this was too generic – you remove a lock and all of your resources are open for accidental deletion. So I settle on adding locks per Resource Group.

Continue reading

Amazon Alexa. First impressions

Recently I purchased Amazon Alexa, just for fun. Initially wife wanted a radio or a Bluetooth speaker on kitchen. And Alexa was cheap enough to use as a speaker/radio.

On the first day I’ve asked it a bunch of questions and got a lot of rather disappointing “hm.. I don’t know that one”. Yeah, sure it can tell me weather and news briefing. Kitchen timer is rather useful (unless it mishears you and resets it instead of pausing).

I’ve tried a bunch of skills and none of them were particularly good/useful. Idea was to get a cook-book, but nothing descent was available (there are Allrecipies, but not available in UK).

And for listening to a music – that’s another disappointment. Turns out that all my MP3s I’ve collected over the years are worthless here. To be able to listen to a music I need to purchase one of the streaming services (Amazon Music or Spotify). But I want my music, not streamed. I’ve wasted a lot of time searching for solution. There were a few options. There is Synology (of which I’m an owner) skill, but that’s been only released in October 2017 and not yet available. There is Plex server, but the this skill does not let me stream music through Alexa – it is a merely voice remote control for other existing player.

I’ve seen a lot of developers telling their way of enabling Alexa to stream their music, but none of it was ever approved to Alexa skills market (why would Amazon allow for that? they sell music service!). And to get that working, involved a lot of work that I did not want to do.

Another thing that I did not like was a way of activating the skills – I had to call it by name and ask for the exact specific command: i.e. Alexa, tell Hive to boost heating to 21 degrees. That’s rather a mouthful. Given I does not always work from the first time, I can turn on my heating on my phone faster. I’d much rather prefer Alexa, boost heating, but that did not always work. Same goes for other skills: Alexa, ask Radioplayer to suggest a station or Alexa, ask [skillname] to do [command-name].
Well, yes, I understand that we are dealing with computers here where precise commands are required, but the last thing I want to remember is that silly skillname to get myself some radio. Granted, there is a built-in TuneIn online radio with hundreds of radios to choose from – problem here to remember (or rather know) the station name I’d like to listen to.

Also I was hoping for advertised shopping list and to-do list to be voice-activated. But my preferred service Wunderlist was supported as a second-class citizen and to add items to my Groceries list I had to go like Alexa, tell Wunder Link to add eggs to my Groceries list. I was hoping for Alexa, add eggs to my shopping list but that is not available. However Todoist.com had a better integration, but I’m not sure I like it better. I grew fond of Wunderlist simplicity and bells-and-whistles of Todoist are overkill for my simple lists.

Anyway, that device turned out to be not that useful as I was hoping it to be.

Here are useful stuff for myself (your mileage may vary):

  • Kitchen timer (rather expensive one)
  • Bluetooth speaker (again, on the expensive side)
  • Online radio (if you know stations names you like)
  • Hive heating control (somewhat flaky)

Disappointments:

  • Unable to play my music without buying a service subscription
  • Voice commands have to be in certain format and having to remember application names and exact format expected is a pain
  • Not clever at all when answering non-wiki questions

So now I’m pondering should I try and build a skill for Alexa (and what should it be?) or just send it back to Amazon?