Categories
Uncategorized

Getting useful during coronavirus pandemic

Since many of us, including me, got more free time during the pandemic because the quarantine and the resulting situation, I decided to help the fight against the coronavirus by using my expertise where applicable. For free. I contributed in four projects.

  1. Joined Slovene volunteer group that decided to keep meaningful and reliable daily statistic data and models about the various aspects of the pandemic. Such data is priceless for keeping on pandemic progress. For some reason our government was and is still unable to provide this data in an useful way (initially it was much worse), hence the motivation. The website is COVID-19 Sledilnik and it is run by many great volunteers. Everything is open source as well and new volunteers are welcome to join. My part is the REST API service that converts manually collected data into a machine friendly way for data consummation. It’s an ASP.NET Core 3.1 web application packed in a docker container. It also features Swagger metadata and Prometheus support. Feel free to consume the data, but some terms apply, check FAQ.
  2. Joined a large group of volunteers and electronics enthusiasts at S5tech.net with 3D printing various protective visors for health workers and laser cutting the transparent part. We created and manufactured visors based on various designs with most popular being Prusa’s one. Each 3D print would take around 3 hours. We distributed for free something like 1000 complete visors before switch to injection moulding because of the huge demand, that solved the production speed greatly. Everything was given away for free and still is. We managed to send them even to a neighboring Italy.
3D printed part
Complete visor
  1. Created a 3D model for Xiaomi Mi Roborock HEPA filter adapter for Decathlon snorkeling mask extension and printed a couple of them. The mask mentioned is a full face mask that should protect one fairly well in case of various viruses, including the SARS-CoV-2. The idea is to mount it on the intake tube and protect yourself from inhaling it or getting it through eyes. The filter in question is HEPA quality, freely available, not expensive and should filter the air pretty well – the classic face masks have the problem that they don’t cover eyes and they were also unavailable due to the shortage at the time. However I never did really test it (how could I?) or wear the mask for real. It was just a fun experiment for something that might come handy in case the situation deteriorated really badly. Anyway, get the model on thingiverse.
    NOTE: You still need to print the mask adapter from the link above.
  1. Joined forces with scientists in search for a COVID-19 cure through distributed computing based on molecular docking. My part is helping them running computations on plenty of CPU cores on Azure cloud. The project is ongoing and crunching numbers as I write this.

That’s it so far. I believe I contributed quite a lot of my free time and hopefully, somebody somewhere will benefit from it health-wise. As for me, I got new experiences, expertise and met a lot of wonderful, resourceful and smart people along the path and if the effort helped even a single person, I’m happy.

Categories
.net Visual Studio Visualizer

A refresh and support for Visual Studio 2019 for Righthand Dataset Debugger Visualizer

I had some spare time and decided to add support for Visual Studio 2019 to Righthand Dataset Debugger Visualizer. Along the path I decided to upgrade underlying DevExpress libraries to a more recent version and switch from Smart Assembly to ILMerge for assembly merging (the only reason is that ILMerge is open source and I wanted to test it). As a collateral I dropped support for Visual Studio 2015 and older versions. One can still use older versions of visualizers for that. The other collateral is that from now on there will be only a merged assembly version available (unless there are problems with merged ones).

So, there you have it, enjoy version 1.0.15

Categories
dart flutter

The perils of flutter’s Table widget

I recently started exploring Flutter for mobile apps, and I have to say that I like it. But that’s a story for another blog post.

Here I just wanted to warn flutter developers against using Table widget. The philosophy of widget itself it’s fine, the problem is that it hides a very insidious bug which happens randomly, or better, just on some devices.

The thing is on certain screen dimensions, app gets stuck in calculating layout forever – it never exists a while loop. Which is the worst bug you can imagine – it happens only on some devices, it isn’t obvious what’s going on (app just becomes unresponsive), it is heavy on battery and there is no useful feedback whatsoever – like an exception being thrown or a log entry – nothing. The bug itself has to do with rounding double numbers which one should really be careful of when requiring precise results.

I reported the bug with a good description and fine folks at google created a PR in the same day or so and it is already merged in the master branch (hopefully the change does the job for good since it relies on a magic number).

TL;DR; Don’t use Table widget before there is a new version of flutter with this fix since your app might bet stuck for good.

Categories
Uncategorized

Building a Raspberry PI cluster – software

  1. Building a Raspberry PI cluster
  2. Building a Raspberry PI cluster – software (this)
The last time I was writing about the hardware aspect of building a Rasberry PI based cluster. Here I’ll describe the software aspect. The installation is based on blog post by Hypriot guys. I’ll just describe my experience and changes I had to make to make it

Ingredients

First I had to configure mikrotik router to act like DHCP server for Rasbperry PIs and to map different ports to connected Raspberry PI’s port 22 (SSH). So I can access them through SSH and they are behind the router.

Burning Hypriot OS image to 4 SD cards

and afterwards assign each on proper hostname (master, node1 .. 3). The later is a bit different if you do it on Windows (you have to modify the configuration on each SD card instead of passing parameters to flashing tool).

Kubernetes installation

Pretty much as blog post. However, the first time I did it it wouldn’t install. Installation was stuck at waiting for kubeadm init.
The best way to figure out is to look at Docker logs for problematic containers (you’ll see them marked as restarted or failed) and inspecting kubeadm logs.
Categories
.net Visual Studio

Switching from packages.config to PackageReference for .NET projects

Recently NuGet introduced a new way of handling packages within a project. Instead of stuffing references in a separate packages.config file, it introduced storing package references right in the project file instead.

There are several benefits (really, read the hyperlinked document) to that, the biggest one from my perspective is that it doesn’t pollute NuGet packages list anymore. Previously, if you installed a package that referenced many transitive packages, then the package manager would show all of them at the same level. The worse case was when you referenced a .NET Standard package to a Xamarin application – in that case you could end up with like 20+ additional packages.

Example: adding (my favorite IoC container) Autofac to a Xamarin Android project would yield all these guys:

Not funny, eh?

So, the PackageReference way will still reference all those but it won’t pollute your NuGet packages list anymore. Plus it clearly shows the top level packages under references, like this:

How does one turn on PackageReference mode?

For new projects

I suggest you set PackageReference as default mode using Tools/Options…/NuGet Package Manager window. Note that default is still package.config.

For existing projects

you should migrate packages.config file as described here. You need Visual Studio 2017 Preview 3 or newer.
That’s it – no more polluted lists and many other benefits!

Categories
Docker Hardware Microcontroller Virtualization

Building a Raspberry PI cluster


Motivation

Partially for learning, partially because it might come handy, I decided to build my own Rasbperry PI cluster that would run HypriotOS and Kubernetes. If you search the web you’ll see others doing it and I used them as a knowledge source. Some are outdated and perhaps sharing my experience might help somebody. Anyway, here is my story starting with

Hardware

  • 4x Raspberry PI 3
  • 4x 32GB microSD – the faster the better
  • 4x network cables
  • 4x USB cables
  • Anker 5 port USB charger
  • Mikrotik hEX router
  • partially self-designed, self 3d printed stack (open source)
I’ve decided to go with 4 Raspberries because I have got hEX router which has 5 ports and 4 of them seem enough for experimenting anyway. Make also sure to get short USB and network cables. The later should be flat to consume less space. Those are sadly hard to get in Slovenia, perhaps your best bet is an online shop somewhere (in the EU). Anker is a good USB charger that shouldn’t have problems feeding the hardware but any powerful enough would do. Also if you manage to find an USB powered router, you don’t need second 220V outlet for the router (currently I need two of these – one for the router and the other for the USB power charger) and have instead a short USB cable just like Raspberries do.

The biggest challenges

Getting short and flat network cables wasn’t easy. Online shops outside of Slovenia will help.
Manufacturing and designing the stack that keeps everything together. I’ve based it on an existing one, but enhanced Raspberry holder and created a compatible holder for both Anker USB charger and mikrotik hEX. I missed one thing though – replacing microSD cards is not easy – I’ve ended up using tweezers. If I ever update the design, I’ll definitely make it easier. But overall it is a solid stack and should do the job just fine.

Connecting the beast

Not much here, router and USB charger need to be powered trough an outlet, all Raspberries need both network cable connected to router and USB one to the USB charger and that’s it. Lights will blink and that’s it.
Next post will deal with HypriotOS nad Kubernetes installation.
Categories
.net C#

About in parameter modifier on value type, properties and defensive copy

in parameter modifier was introduced in C# 7.2. It lets you pass (value) types by reference but at the same time protect you against modifying the actual instance.

Here is what What’s new in C# 7.2 says about it:

The in modifier on parameters, to specify that an argument is passed by reference but not modified by the called method.

Basically compiler protects you against modification of the instance in two ways:

  • when you try to change a field directly compiler will throw an error
  • when you call an instance method, compiler will create a defensive copy of the instance and run that method on the copy

But what happens when calling instance properties? Will compiler create a defensive copy as well? Even for autoimplemented getters? That’s the question I’ve got on my presentation and I wasn’t sure about it. On one hand properties in general can implement modification code and in that sense they aren’t safe just like methods aren’t. On the other hand autoimplemented getters don’t implement any modification code.

If I had to guess I’d say there is no need for defensive copies when dealing with autoimplemented getters, while in other cases compiler will resort to defensive copies.

After few experiments and using Reflector to inspect the generated code it turns out that compiler will use defensive copies with properties always, even with autoimplemented getters. You can also check it out with SharpLab.io, which is a great way into digging into (experimental) C#.

Looks like there is some room for improvement.

Categories
Xamarin

Fresh new Xamarin.Forms application created from template yields a ton of errors

I created a new Android and iOS/NETStandard Xamarin.Forms application with Visual Studio 2017 15.5.4 and immediately got an exclamation mark on Dependencies node in Common project. Trying to build the solution I got like three errors for start. They were saying something along

error : Assets file ‘[APPPATH]\obj\project.assets.json’ not found. Run a NuGet package restore to generate this file.

Since I had no idea what that message wanted to tell me I went checking for references and I quickly saw that nor Android nor iOS had any NuGet reference present albeit the packages were listed as installed. So, no packages for some reason. I quickly dismissed the possibility of bad “new Xamarin.Forms project” template – Internet would be screaming in such case.
After tinkering a bit, I saw that Package Manager window was saying that it can’t find a reference to NuGet Source for one of my sources. Which was correct, but I wasn’t using that source at all.

It turns out that once disabling that (faulty) source, NuGet was able to restore the packages and project was building.
Actually it was a combination of two problems combined – one was that missing source that prevented NuGet to download packages and the other problem was that the required NuGet packages weren’t cached locally on my computer – if they were I believe it would work regardless of the faulty source.

Categories
.net Visual Studio

Troubleshooting Live Unit Test build failure

It happens that I have a .NET 4.6.2 solution including Unit Test projects that builds just fine. However, when starting Live Unit Test it would complain build completed (failed) for some reason. Which is weird since the solution builds fine.

I started searching for the reason of this mysterious build failure. First thing to do is to enable verbose Live Unit Test logging: Tools/Options…/Live Unit Testing -> Logging Level. Once set to verbose it become obvious that Live Unit Test BuildManager had problems with some referenced third party assemblies, specifically (in my case) with NUnit and Moq. Errors were like this:

[09:02:50.728 Verbose] – BuildManager – MY_TEST_PROJECT_PATH\SomeFile.cs(1,7): error CS0246: The type or namespace name ‘NUnit’ could not be found (are you missing a using directive or an assembly reference?)

But why wouldn’t it find these Assemblies where VS has no problem finding them. Note: I added these two (and other) assemblies through NuGet.
I went looking where the problematic references actually point (Solution Explorer, Test Project, References) and saw something odd. Instead of pointing to a some path under NuGet Packages directory they were pointing to build output directory. At some point in the past VS decided that it has to change the path to the assemblies for some reason. Probably it couldn’t find them at original location and decided to find the only ones it could – ones from the recent build in the build output directory. Which is a bad move from Visual Studio and one that most certainly causes problems.

At the end the solution was rather easy once I discovered the reason. I simply upgraded NuGet packages to a newer version. Reinstall would also work.

Categories
.net

More about SharpRedux

Since last post about SharpRedux I added GettingStarted sample, did a bit of refactoring and added quite some documentation.

Go check the documentation and play with both samples.

Next step is to create a centralized hub for pushing actions and reading from into a visulizer. This will make visualizer and development of (mobile) apps much better experience. Also collecting history from apps running in the wild. Stay tunned.