A side-by-side comparison of three Maximum LINQ Aproaches

Let’s perform an analysis on different Methods of attaining the maximum value of a list of elements.

One of the limitations that I’ve encountered of the Max LINQ statement is the inability to handle empty sequences. Usually, what I’ve seen is the use of Order By Descending and First Or Default to grab the maximum value of an array. This sorting algorithm approach, while common, is O(n lg n). The Maximum LINQ query, in comparison is O(n).

But are they substantially better when dealing with possible empty sequences?

Method 1: OrderByDescending
Method 2: DefaultIfEmptyMethod
Method 3: DetectIfEmpty Method
Performance Analysis

From the analysis, the OrderByDescending and FirstOrDefault when benchmarked is on average 27us faster on an array of 5000 elements. But what’s fastest is using the Any Clause and null check. At approximately 20 us and 50 us from Order By Descending and Default If Empty method.

What is interesting is the memory allocation of the Maximum and DefaultIfEmpty LINQ is half of the allocation of the OrderByDescending. But DetectIfEmpty method is right in between the two, at 160 B compared to 105 B for the DefaultIfEmpty and 200 B for the OrderByDescending.

While the Algorithmic complexity of the Max is much better than the Sort Algorithm at O(n) vs O(n lg n). The introduction of the DefaultIfEmpty method and the need for a null check in the Max clause, increases the Algorithmic Complexity. We do see a 50% reduction in Allocated Memory. While not the prettiest, evaluating the query and performing a null check and an any clause to grab the maximum value is a lot more time performant than both methods, although not as space efficient.

A C# Back End Developer’s Dream

In one of my Master classes, a teammate and I were going through the process of pushing API Models into C# for NewtonSoft JSON library through Visual Studio. I began to search online to see if there’s a better way of doing this. After all, Microsoft must have developed a way to mass migrate Models. Sure enough there is. This video details the process:

VMware and Docker

After installing Docker through Microsoft Visual Studio, you may have noticed VMware claims Hyper-V Hypervisor is installed.

If like me, you’ve already removed Hyper-V feature from Windows and are wondering why this error comes up. You might want to read on to find a way to use your VMware

The first step, you may have examined the Windows Feature to come across this perplexing setting. Hyper-V looks disabled. Why this error.

These are troubleshooting steps

  • Go to Command Prompt as Admin and type in systeminfo 
  • If this claims that a Hyper Visor has been detected try the below
  • In PowerShell as Admin type
  • Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
  • DISM /Online /Disable-Feature:Microsoft-Hyper-V
  • In Command Prompt
  • bcdedit /set hypervisorlaunchtype off
  • Now Restart your computer and discover that VMWare now works

Source:

How to Uninstall or Disable Hyper-V in Windows (nakivo.com)

Raspberry Pi: Motion Capture

2 years ago I successfully set up Pikrellcam for the Raspberry Pi for motion capture detection. An open source package that sets up nginx and a custom PHP Web application that communicates with a series of server side scripts written in C to analyze the content coming through the Camera.

Raspberry Pi Camera Module V2 with Open Source PiKrellCam detecting reflections of water off ceiling.

Setting up Automated Mailing in Canvas LMS: A Quick Guide

I was exploring StackOverflow and noticed this was a common issue. After a few explorations of my own. I found the answer.

Configuration

sysadmin@appserver:/var/canvas$ sudo vi config/outgoing_mail.yml

You’ll need to replace the production part with something along the lines of the following. If you’re using Gmail, you will need to create an application password. More information on that is provided in the bottom of this post.

 production:
    enable_starttls_auto: true
    address: smtp.gmail.com
    port: 587
    user_name: USERNAME@gmail.com
    password: PASSWORD
    authentication: plain        # plain, login, or cram_md5
    domain: smtp.gmail.com
    outgoing_address: USERNAME@gmail.com
    default_name: Instructure Canvas

Automated Jobs Daemon

You first must set up the Automated Jobs Daemon with the following:

sysadmin@appserver:/var/canvas$ sudo ln -s /var/canvas/script/canvas_init /etc/init.d/canvas_init
sysadmin@appserver:/var/canvas$ sudo update-rc.d canvas_init defaults
sysadmin@appserver:/var/canvas$ sudo /etc/init.d/canvas_init start

Update Configuration

If for whatever reason you need to update the configuration.

sysadmin@appserver:/var/canvas$ sudo /etc/init.d/canvas_init restart

Setting up Gmail for Outgoing Mail

Regarding setting up outgoing mail through gmail:

This might be a new update, but in order for the mail to work correctly, you have to set up an application specific password with Gmail. There are a ton of tutorials online on how to do that… here it is from Google:

https://support.google.com/accounts/answer/185833?hl=en

Troubleshooting

If you’re having any issues, delayed jobs daemon sets up a log file that you can search through

sysadmin@appserver:/var/canvas$ sudo vi log/delayed_job.log

Hope this helps anyone that needs it