<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Antidisestablishmentarianism</title>
    <description>The latest articles on DEV Community by Antidisestablishmentarianism (@antidisestablishmentarianism).</description>
    <link>https://dev.to/antidisestablishmentarianism</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F414696%2F1f6055fd-9d38-4dd9-8e22-594a336977dc.jpg</url>
      <title>DEV Community: Antidisestablishmentarianism</title>
      <link>https://dev.to/antidisestablishmentarianism</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/antidisestablishmentarianism"/>
    <language>en</language>
    <item>
      <title>Stop using Google to lookup error codes and write your own error lookup class.</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Sun, 07 Jan 2024 15:53:38 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/stop-using-google-to-lookup-error-codes-and-write-your-own-error-lookup-class-2369</link>
      <guid>https://dev.to/antidisestablishmentarianism/stop-using-google-to-lookup-error-codes-and-write-your-own-error-lookup-class-2369</guid>
      <description>&lt;p&gt;Creating a class to decode EVERY Windows error code in C#.&lt;/p&gt;

&lt;p&gt;I got tired of dealing with NTStatus, HResults, Win32 error codes, etc., so I wrote my own error lookup program.&lt;/p&gt;

&lt;p&gt;First, we need the error codes. There are multiple resources that have all the error codes, but the easiest way to obtain them is to download the Microsoft Error Lookup Tool and export the embedded error codes to a .csv file. You can get it from &lt;a href="https://www.microsoft.com/en-US/download/details.aspx?id=100432"&gt;https://www.microsoft.com/en-US/download/details.aspx?id=100432&lt;/a&gt; or search for it if the link is broken.&lt;/p&gt;

&lt;p&gt;You can export all of the error codes with the command: Err_6.4.5.exe /:outputtoCSV &amp;gt; errors.txt.&lt;/p&gt;

&lt;p&gt;Next, I compress the file. I am choosing Brotli compression. There is a method in the Utils class to compress the file.&lt;/p&gt;

&lt;p&gt;After compressing the file, I embed the file as a resource in Visual Studio Resources property page.&lt;/p&gt;

&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Only show ntstatus and winerror records? Y/N. n

Enter error to lookup, e.g. 1234, 0x0a345.
123

Source: bugcodes.h  Error Code: Dec: 123  Hex: 7B
Symbolic Name(s): INACCESSIBLE_BOOT_DEVICE
Description(s): N/A

Source: netmon.h  Error Code: Dec: 123  Hex: 7B
Symbolic Name(s): NMERR_SECURITY_BREACH_CAPTURE_DELETED
Description(s): N/A

Source: winerror.h  Error Code: Dec: 123  Hex: 7B
Symbolic Name(s): ERROR_INVALID_NAME
Description(s): The filename, directory name, or volume label syntax is incorrect.

Enter error to lookup, e.g. 1234, 0x0a345.
0x80070643

As win32 error:

Source: winerror.h  Error Code: Dec: 1603  Hex: 643
Symbolic Name(s): ERROR_INSTALL_FAILURE
Description(s): Fatal error during installation.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following code is heavily commented and written using .NET 8, but would only require very minor changes to downgrade.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System.Globalization;
using System.IO.Compression;
using System.Text;
using static Errors.Utils;

namespace Errors;

internal class ErrorRecord
{
    private int ErrorCode;
    private string? SymbolicName, Description, Source;

    private static readonly CultureInfo culture = new("en-US");
    private static readonly Dictionary&amp;lt;int, List&amp;lt;ErrorRecord&amp;gt;&amp;gt; errorlist = CreateErrorDatabase();

    internal static Dictionary&amp;lt;int, List&amp;lt;ErrorRecord&amp;gt;&amp;gt; CreateErrorDatabase()
    {
        Dictionary&amp;lt;int, List&amp;lt;ErrorRecord&amp;gt;&amp;gt; dict = [];

        //Retrieve and decompress embedded resource.
        using MemoryStream errorstream = new(Properties.Resources.errors);
        using BrotliStream decompressStream = new(errorstream, CompressionMode.Decompress);
        using StreamReader reader = new(decompressStream);

        List&amp;lt;ErrorRecord&amp;gt; initialrecordset = [];

        IEnumerable&amp;lt;string&amp;gt; allrecords = reader.ReadToEnd()
            .Replace("N/A", "", StringComparison.Ordinal)         //Remove "N/A" in descriptions. When we run .Distinct it will eliminate duplicate records that previously had one with N/A and the other had no description.
            .Replace("\"", "", StringComparison.Ordinal)          //Remove all quotes from text.
            .Replace("&amp;amp;apos;", "\'", StringComparison.Ordinal)    //Replace unicode apostrophe with corresponding character.
            .Replace("&amp;amp;quot;", "\"", StringComparison.Ordinal)    //Replace unicode quote with corresponding character.
            .Replace("&amp;amp;#10;", " ", StringComparison.Ordinal)      //Replace unicode line feed with a space.
            .Replace("&amp;amp;lt;", "&amp;lt;", StringComparison.Ordinal)       //Replace unicode 'less than' character with corresponding character.
            .Replace("&amp;amp;gt;", "&amp;gt;", StringComparison.Ordinal)       //Replace unicode 'greater than' with corresponding character.
            .Replace("&amp;amp;amp;", "&amp;amp;", StringComparison.Ordinal)      //Replace unicode 'and' with corresponding character.
            .Split(Environment.NewLine)                           //Split into those sweet error records, baby!
            .Skip(1)                                              //Remove duplicates.
            .Distinct()                                           //Skip header row.
            .Where(l =&amp;gt; !string.IsNullOrEmpty(l));                //Remove blank line at the end file.

        foreach (string? line in allrecords)
        {
            string[] currentRow = line.Split(",");                //Split records into fields.

            initialrecordset.Add(new ErrorRecord()                //Parse fields and add to new records.
            {
                ErrorCode = int.Parse(currentRow![0].Replace("0x", "", StringComparison.Ordinal), NumberStyles.HexNumber, culture),

                SymbolicName = currentRow[1],

                Description = currentRow[2]
                .Replace("&amp;amp;#44;", ",", StringComparison.Ordinal)  //Replace unicode comma with comma. We must do this AFTER splitting the records into fields as they are comma delimmited.
                .CompactWhitespace(),                             //Clean up descriptions.

                Source = currentRow[3]
            });
        }

        //Exclude all records that have no description but have a duplicate with the same Source, SymbolicName, and ErrorCode that has a description.
        //These only show up in pairs in the csv and there are no pairs where both have an empty description.
        List&amp;lt;ErrorRecord&amp;gt; ErrorRecords = initialrecordset.Except(initialrecordset
            .GroupBy(x =&amp;gt; new { x.Source, x.SymbolicName, x.ErrorCode })
            .Where(c =&amp;gt; c.Count() &amp;gt; 1).SelectMany(a =&amp;gt; a)
            .Where(d =&amp;gt; string.IsNullOrEmpty(d.Description)))
            .ToList();

        var DuplicateRecords = ErrorRecords                       //Create set of records that contains records with the same Source and ErrorCode but different SymbolicNames.
            .GroupBy(x =&amp;gt; new { x.Source, x.ErrorCode })
            .Where(c =&amp;gt; c.Count() &amp;gt; 1)
            .ToList();

        List&amp;lt;ErrorRecord&amp;gt; CombinedDuplicates = [];

        foreach (var duplicates in DuplicateRecords)
        {
            string sb = string.Empty, d = string.Empty;
            int count = 0;                                        //Number SymbolicNames and Descriptions to make records easier to read.

        foreach (var duplicates in DuplicateRecords)
        {
            string sb = string.Empty, d = string.Empty;
            int count = 0;                                        //Number SymbolicNames and Descriptions to make records easier to read.
            foreach (ErrorRecord? record in duplicates)
            {
                sb += $"[{++count}] {record.SymbolicName}  "; //Combine all SymbolicNames from each duplicate in DuplicateRecords and number consecutively.

                d += !string.IsNullOrEmpty(record.Description) ? $"[{count}] {record.Description}  " : $"[{count}] N/A  ";  //Combine all Descriptions from each duplicate in DuplicateRecords and number consecutively.
            }

            //Add combined records to new record list.
            CombinedDuplicates.Add(new() { ErrorCode = duplicates.First().ErrorCode, Source = duplicates.First().Source, Description = d, SymbolicName = sb });
        }

            //Add combined records to new record list.
            CombinedDuplicates.Add(new() { ErrorCode = duplicates.First().ErrorCode, Source = duplicates.First().Source, Description = d, SymbolicName = sb });
        }

        //Remove DuplicateRecords from ErrorRecords and concatenate result with CombinedDuplicates,
        ErrorRecords = ErrorRecords.Except(DuplicateRecords.SelectMany(a =&amp;gt; a)).Concat(CombinedDuplicates).ToList();

        //Add to dictionary for fast retrieval.
        foreach (ErrorRecord item in ErrorRecords)
            if (dict.TryGetValue(item.ErrorCode, out List&amp;lt;ErrorRecord&amp;gt;? er))
                er.Add(item);
            else
                dict.Add(item.ErrorCode, [item]);

        return dict;
    }


    //Retrieve all records for a specific error.
    public static List&amp;lt;ErrorRecord&amp;gt; GetErrorRecords(int error) =&amp;gt; errorlist.TryGetValue(error, out List&amp;lt;ErrorRecord&amp;gt;? value) ? value : [];


    //Retrieve all records from a specific error and header, e.g., ntstatus.h.
    public static ErrorRecord? GetErrorRecordFromHeader(int error, string header) =&amp;gt; errorlist.TryGetValue(error, out List&amp;lt;ErrorRecord&amp;gt;? value) ?
        value.Find(x =&amp;gt; string.Equals(x.Source, header, StringComparison.OrdinalIgnoreCase)) : null;


    //Override .ToString method for console output.
    public override string ToString() =&amp;gt; $"Source: {Source}  Error Code: Dec: {ErrorCode}  Hex: {ErrorCode:X}\nSymbolic Name(s): " +
        $"{SymbolicName}\n{(!string.IsNullOrEmpty(Description) ? $"Description(s): {Description}\n" : $"Description(s): N/A\n")}";


    //Retrieve error string from a specific header, e.g., ntstatus.h, for public use.
    public static string GetErrorFromHeader(int error, string header)
    {
        string? recordtostring;
        return errorlist.TryGetValue(error, out List&amp;lt;ErrorRecord&amp;gt;? value) &amp;amp;&amp;amp;
            (recordtostring = value.Find(x =&amp;gt; string.Equals(x.Source, header, StringComparison.OrdinalIgnoreCase))?.ToString()) != null
            ? recordtostring : $"Dec: {error} Hex: {error:X} does not exist in the error database for the specified header.";
    }


    //Example method to retrieve errors from the command line. Also converts error to an HResult counterpart if applicable, similar (but apparently not identical to the Microsoft Error Lookup program).
    public static void GetErrors(bool ans)
    {
        int lookup = GetInt(caption: "Enter error to lookup, e.g. 1234, 0x0a345."), win32error = lookup &amp;amp; 0xFFFF;

        List&amp;lt;ErrorRecord&amp;gt; e1 = ans ? GetErrorRecords(lookup).Where(x =&amp;gt; x.Source is "ntstatus.h" or "winerror.h").ToList() : GetErrorRecords(lookup),
            e2 = (lookup &amp;amp; 0xFFFF0000) == 0x80070000 ? GetErrorRecords(win32error).Where(x =&amp;gt; x.Source is "winerror.h").ToList() : [];

        e1.PrintList();

        if (e2.Count != 0)
        {
            Console.WriteLine($"As win32 error:\n");
            e2.PrintList();
        }

        if (e1.Count == 0 &amp;amp;&amp;amp; e2.Count == 0)
            Console.WriteLine("There are no matching errors in the error database.\n");
    }
}


internal static class Utils
{
    private static readonly CultureInfo culture = new ("en-US");

    //Compress .csv file before embedding.
    internal static void CompressFile(string name)
    {
        byte[] bytes = File.ReadAllBytes(name);

        using MemoryStream stream = new();

        using (BrotliStream brotli = new(stream, CompressionLevel.Optimal))
            brotli.Write(bytes, 0, bytes.Length);

        File.WriteAllBytes(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + Path.GetFileNameWithoutExtension(name) + ".brotli", stream.ToArray());
    }

    //Read from command line until a valid hexadecimal or number is read.
    internal static int GetInt(int min = int.MinValue, int max = int.MaxValue, string caption = "")
    {
        if (!string.IsNullOrWhiteSpace(caption))
            Console.WriteLine(caption);

        string? ans;
        int num;

        while (string.IsNullOrWhiteSpace(ans = Console.ReadLine()) || !(ans.Contains('x', StringComparison.Ordinal) || ans.Contains('X', StringComparison.Ordinal)
            ? int.TryParse(ans.Replace("0x", "", StringComparison.Ordinal).Replace("0X", "", StringComparison.Ordinal), NumberStyles.HexNumber, culture, out num)
            : int.TryParse(ans, out num)) || !(num &amp;gt;= min &amp;amp;&amp;amp; num &amp;lt;= max)) ;

        Console.WriteLine();

        return num;
    }

    //Read from command line for Y/N response..
    internal static bool GetYN(string caption = "")
    {
        if (!string.IsNullOrWhiteSpace(caption))
            Console.Write(caption);

        char x = Console.ReadKey().KeyChar;

        Console.WriteLine('\n');

        return x is 'y' or 'Y';
    }

    //A simple print extension.
    internal static void PrintList&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;T&amp;gt; col)
    {
        foreach (T item in col)
        {
            string? line = item?.ToString();

            if (!string.IsNullOrEmpty(line))
                Console.WriteLine(line);
        }
    }

    //An extension to compact the whitespace in a string.
    internal static string CompactWhitespace(this string str)
    {
        if (string.IsNullOrWhiteSpace(str))
            return string.Empty;

        str = str.Trim();

        StringBuilder sb = new();

        for (int i = 0; i &amp;lt; str.Length - 1; i++)
        {
            if (char.IsWhiteSpace(str[i]) &amp;amp;&amp;amp; char.IsWhiteSpace(str[i + 1]))
                continue;

            _ = char.IsWhiteSpace(str[i]) ? sb.Append(' ') : sb.Append(str[i]);
        }

        return !char.IsWhiteSpace(str[^1]) ? sb.Append(str[^1]).ToString() : sb.ToString();
    }
}

internal class Program
{
    static void Main()
    {
        bool ans = GetYN(caption: "Only show ntstatus and winerror records? Y/N. ");

        while (true)
            ErrorRecord.GetErrors(ans);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>csharp</category>
      <category>utilities</category>
    </item>
    <item>
      <title>Restarting (not starting) you C# application from itself with administrator privileges.</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Wed, 18 Jan 2023 20:40:42 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/restarting-not-starting-you-c-application-from-itself-with-administrator-privileges-4k6d</link>
      <guid>https://dev.to/antidisestablishmentarianism/restarting-not-starting-you-c-application-from-itself-with-administrator-privileges-4k6d</guid>
      <description>&lt;p&gt;I recently came across a situation where I wanted to restart my program with administrator privileges if it was run with no parameters so the program could execute an install sequence.&lt;br&gt;
I used the following code in a .NET 7.0 Console application...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System.Diagnostics;
using System.Security.Principal;

class Stuff
{
    static void Install()
    {
        try
        {
            //check if we are running as administrator currently
            if (!new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator))
            {
                //Start new process as administrator. Environment.ProcessPath is the path of what we are currently running.
                Process.Start(new ProcessStartInfo { FileName = Environment.ProcessPath, UseShellExecute = true, Verb = "runas" });

                //Exit current process
                Environment.Exit(0);
            }
        }
        //if user selects "no" from adminstrator request.
        catch
        {
            Console.WriteLine("Administrative rights are required for installing this application.\nPress any key to exit.");
            Console.ReadKey(true);
            Environment.Exit(0);
        }

        //Do stuff...

        Console.WriteLine("Install complete\nPress any key to exit\n");
        Console.ReadKey(true);
        Environment.Exit(0);
    }

    public static void Main(string[] args)
    {
        if (args.Length == 0)
            Install();
        else
        {
            //Do stuff...
        }

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>discuss</category>
      <category>softwareengineering</category>
      <category>cicd</category>
    </item>
    <item>
      <title>A BCryptDeriveKeyPBKDF2 example in C++.</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Tue, 10 Jan 2023 00:33:22 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/a-bcryptderivekeypbkdf2-example-in-c-4ihh</link>
      <guid>https://dev.to/antidisestablishmentarianism/a-bcryptderivekeypbkdf2-example-in-c-4ihh</guid>
      <description>&lt;p&gt;I had a heck of a time finding a simple example of this function. I eventually made my own...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#pragma comment(lib, "bcrypt.lib")
#include &amp;lt;Windows.h&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;iostream&amp;gt;

int main()
{
    std::string password = "This is the password that will be encrypted";
    std::string salt = "EncryptionSalt";
    NTSTATUS Status;
    BYTE DerivedKey[64];

    BCRYPT_ALG_HANDLE handle;
    Status = BCryptOpenAlgorithmProvider(&amp;amp;handle, BCRYPT_SHA512_ALGORITHM, NULL, BCRYPT_ALG_HANDLE_HMAC_FLAG);

    if (Status != 0)
    {
        std::cout &amp;lt;&amp;lt; "BCryptOpenAlgorithmProvider exited with error message " &amp;lt;&amp;lt; Status;
        goto END;
    }

    Status = BCryptDeriveKeyPBKDF2(handle, (BYTE*)password.data(), password.length(), (BYTE*)salt.data(), 8, 2048, DerivedKey, 64, 0);

    if (Status != 0)
    {
        std::cout &amp;lt;&amp;lt; "BCryptDeriveKeyPBKDF2 exited with error message " &amp;lt;&amp;lt; Status;
        goto END;
    }

    else
        std::cout &amp;lt;&amp;lt; "Operation completed successfully. Your encrypted key is in variable DerivedKey.";

    BCryptCloseAlgorithmProvider(handle, 0);

END:;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cpp</category>
      <category>c</category>
      <category>bcrypt</category>
      <category>crypto</category>
    </item>
    <item>
      <title>Shortest C# program to display IP addresses in a range.</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Mon, 11 Jul 2022 15:47:00 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/shortest-c-program-to-display-ip-addresses-in-a-range-565k</link>
      <guid>https://dev.to/antidisestablishmentarianism/shortest-c-program-to-display-ip-addresses-in-a-range-565k</guid>
      <description>&lt;p&gt;Just for fun, I tried to write the shortest code to take two IP addresses from the command line and list the IP addresses between them.&lt;/p&gt;

&lt;p&gt;This doesn't check for errors or broadcast addresses or anything of the like, hence the "fun" part.&lt;/p&gt;

&lt;p&gt;If you can make this shorter please show your skills in the comments.&lt;/p&gt;

&lt;p&gt;This is written in C# 10 with top level statements enabled, so it is a complete programs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uint p(string b) =&amp;gt; BitConverter.ToUInt32(b.Split(".").Reverse().Select(byte.Parse).ToArray());

for (var ip = p(args[0]); ip &amp;lt;= p(args[1]); ip++)
    Console.WriteLine(string.Join(".", BitConverter.GetBytes(ip).Reverse()));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>csharp</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>How to waste an afternoon writing bad code to help your girlfriend cheat at Wordle...</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Sat, 07 May 2022 07:55:30 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/how-to-waste-an-afternoon-writing-bad-code-for-your-girlfriend-to-cheat-at-her-wordle-app-5bh4</link>
      <guid>https://dev.to/antidisestablishmentarianism/how-to-waste-an-afternoon-writing-bad-code-for-your-girlfriend-to-cheat-at-her-wordle-app-5bh4</guid>
      <description>&lt;p&gt;As the title says, I wrote this to help my GF cheat at wordle.&lt;/p&gt;

&lt;p&gt;Is the code commented? Heck no!&lt;br&gt;
Is their error checking? Hardly any!&lt;br&gt;
Am I incorrectly relying on a dictionary to preserve the order of keys as they are added? Yup!&lt;br&gt;
And lets not forget my use of a goto statement and too many globals!&lt;/p&gt;

&lt;p&gt;The app she is using is the android Lion Studios Wordle app, and I don't know what word list they are using. The closest I have found is the NASPA NSWL2020 word list, but there are still some words that appear in that list that the app doesn't recognize. (Incidentally, the New York Times uses the Collins word list)&lt;/p&gt;

&lt;p&gt;Lets say your first word is "reads" and it shows that you have have an 'r' and an 'a', with the 'a' being in the correct location.&lt;br&gt;
the parameters would be entered as such:&lt;/p&gt;

&lt;p&gt;wordlesolver ra ed 11a11 r1&lt;/p&gt;

&lt;p&gt;First parameter: Indicates letters in word.&lt;br&gt;
Second parameter: Indicates letters not in word.&lt;br&gt;
Third parameter: Show where letters are in word.&lt;br&gt;
Fourth and above: Shows which letters are not in specified positions.&lt;/p&gt;

&lt;p&gt;You can skip the first and second parameters by entering a '0', e.g., wordlesolver 0 0 11a11 r1.&lt;br&gt;
You can skip the third parameter completely, and to indicate multiple letters that are not in indicated positions you can continue adding 2 character info, e.g.,&lt;br&gt;
wordlesolver ra ed r1 t2 g4&lt;/p&gt;

&lt;p&gt;wordlesolver ril eadspotf 11111 r1 i2 l2 l3 i3 r4 will produce the result "lyric".&lt;/p&gt;

&lt;p&gt;Use the up arrow to get the last command and add the additional information.&lt;/p&gt;

&lt;p&gt;Yes, the parameters could be parsed wayyyyyyyyy better, probably by just listing the words with the a number to indicate letters that are in the word and are in the correct spot, but this is about as much effort as I was willing to put into it.&lt;/p&gt;

&lt;p&gt;Suggested words are created by the following method...&lt;br&gt;
The first # is the number of letters in the word that have not been used and are in the possible solution list. The remaining numbers are the letter frequency score I generate for the word. Words are listed in score order. In theory I would only need to list one word, but because the app occasionally doesn't recognize a word, multiple are listed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static Dictionary&amp;lt;string, int&amp;gt; word_dict = File.ReadAllLines(@"c:\a\words.txt").Distinct().OrderBy(x =&amp;gt; x).ToDictionary(x =&amp;gt; x, x =&amp;gt; 0);
    static Dictionary&amp;lt;char, int&amp;gt; letter_dict = new() { { 'a', 0 }, { 'b', 0 }, { 'c', 0 }, { 'd', 0 }, { 'e', 0 }, { 'f', 0 }, { 'g', 0 }, { 'h', 0 }, { 'i', 0 }, { 'j', 0 }, { 'k', 0 }, { 'l', 0 }, { 'm', 0 }, { 'n', 0 }, { 'o', 0 }, { 'p', 0 }, { 'q', 0 }, { 'r', 0 }, { 's', 0 }, { 't', 0 }, { 'u', 0 }, { 'v', 0 }, { 'w', 0 }, { 'x', 0 }, { 'y', 0 }, { 'z', 0 } };
    static List&amp;lt;string&amp;gt; include = new();

    static void ParseArgs(string[] args)
    {
        int len = args.Length;

        foreach (string word in word_dict.Keys)
        {
            if (len &amp;gt; 2 &amp;amp;&amp;amp; args[2].Length == 5)
                for (int j = 0; j &amp;lt; 5; j++)
                    if (char.IsLetter(args[2][j]))
                        if (word[j] != args[2][j])
                            goto end;

            if (len &amp;gt; 0 &amp;amp;&amp;amp; args[0] != "0")
                for (int j = 0; j &amp;lt; args[0].Length; j++)
                    if (!word.Contains(args[0][j]))
                        goto end;

            if (len &amp;gt; 1 &amp;amp;&amp;amp; args[1] != "0")
                for (int j = 0; j &amp;lt; args[1].Length; j++)
                    if (word.Contains(args[1][j]))
                        goto end;

            if (len &amp;gt; 3)
                for (int j = 0; j &amp;lt; len - 3; j++)
                    if (word[args[j + 3][1] - '0' - 1] == args[j + 3][0])
                        goto end;

            include.Add(word);

        end:;
        }
    }


    static void GetSolutions(string first)
    {
        foreach (string word in include)
            for (int i = 0; i &amp;lt; 5; i++)
                if (!first.Contains(word[i]))
                    letter_dict[word[i]]++;

        letter_dict = letter_dict.Where(x =&amp;gt; x.Value &amp;gt; 0).OrderByDescending(x =&amp;gt; x.Value).ToDictionary(x =&amp;gt; x.Key, x =&amp;gt; x.Value);

        if (include.Count &amp;lt;= 20)
        {
            Console.WriteLine("All possible solutions: ");
            foreach (string item in include)
                Console.Write($"{item} ");
        }
        else
            Console.Write($"There are {include.Count} possible solutions. ");

        Console.WriteLine("\n");
    }


    static void GetSuggestedWords()
    {
        foreach (string word in word_dict.Keys)
            foreach (char item in letter_dict.Keys.Distinct())
                if (word.Contains(item))
                    word_dict[word] += letter_dict[item] + 100000;

        word_dict = word_dict.OrderByDescending(x =&amp;gt; x.Value).ToDictionary(x =&amp;gt; x.Key, x =&amp;gt; x.Value);

        if (word_dict[word_dict.Keys.First()] &amp;gt;= 200000)
        {
            Console.WriteLine("Suggested word / Word score:");
            int count = 0;

            foreach (string item in word_dict.Keys)
                if (word_dict[item]! &amp;gt;= 200000)
                {
                    Console.Write("{0} {1} ", item, word_dict[item]);
                    count++;
                    if (count == 9)
                        break;
                }
        }

        Console.WriteLine("\n");
    }


    static void Main(string[] args)
    {
        Console.Clear();

        if (args.Length == 0)
        {
            args = new string[1];
            args[0] = "0";
        }

        ParseArgs(args);
        GetSolutions(args[0]);
        GetSuggestedWords();
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>csharp</category>
      <category>wordle</category>
    </item>
    <item>
      <title>Prime Number Generation Part 2: Deterministic Miller Test For Primality</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Fri, 08 Apr 2022 07:39:14 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/prime-number-generation-part-2-deterministic-miller-test-1hin</link>
      <guid>https://dev.to/antidisestablishmentarianism/prime-number-generation-part-2-deterministic-miller-test-1hin</guid>
      <description>&lt;p&gt;Uses the deterministic Miller test and can test primality for values up to 2^32.&lt;br&gt;
CountPrimes will count primes up to and including a value.&lt;br&gt;
CountPrimesParallel will count all primes up to an exponent of 2 in parallel.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;ppl.h&amp;gt;

//Primes to test against
int witness[] = { 2, 7, 61 };

//number of primes up to exponents of 2
int pp[] = { 1, 2, 4, 6, 11, 18, 31, 54, 97, 172, 309, 564, 1028, 1900, 3512, 6542, 12251, 23000, 43390, 82025, 155611, 295947, 564163, 1077871, 2063689, 3957809, 7603553, 14630843, 28192750, 54400028, 105097565, 203280221 };

inline uint64_t Powmod(uint64_t n, uint64_t e, uint64_t m)
{
    uint64_t x = 1;
    while (e &amp;gt; 0)
    {
        if (e &amp;amp; 1)
            x = x * n % m;

        n = n * n % m;
        e &amp;gt;&amp;gt;= 1;
    }
    return x;
}

// See https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test.
// A direct translation of the deterministic Miller test, NOT the probabilistic variant.
bool MillerTest(uint64_t n)
{
    uint64_t d = n - 1, r = 0;

    while (!(d &amp;amp; 1))
    {
        r++;
        d &amp;gt;&amp;gt;= 1;
    }

    for (int i = 0; i &amp;lt; 3; i++)
    {
        uint64_t a = witness[i];
        uint64_t x = Powmod(a, d, n);

        //triggered if prime is in witness list
        if (x == 0)
            return true;

        if (x == 1 || x == n - 1)
            continue;

        uint64_t j;

        for (j = 1; j &amp;lt; r; j++)
        {
            x = x * x % n;

            if (x == n - 1)
                break;
        }

        if (j == r)
            return false;
    }
    return true;
}

//Count primes up to a specified unsigned 64 bit integer..
void CountPrimes(uint64_t limit)
{
    uint64_t count = 0;
    time_t t1 = time(0);

    for (uint64_t i = 3; i &amp;lt;= limit; i += 2)
        if (MillerTest(i))
            count++;

    std::cout &amp;lt;&amp;lt; "There are " &amp;lt;&amp;lt; count + 1 &amp;lt;&amp;lt; " primes up to " &amp;lt;&amp;lt; limit &amp;lt;&amp;lt; " " &amp;lt;&amp;lt; time(0) - t1 &amp;lt;&amp;lt; " seconds." &amp;lt;&amp;lt; std::endl;
}

//Count primes up to a specified power of 2 in parallel.
void CountPrimesParallel(uint64_t exponent)
{
    time_t t1 = time(0);
    const uint64_t x = exp2l(exponent) / 2;
    std::atomic_uint count = 0;

    concurrency::parallel_for(uint64_t(1), x, [&amp;amp;](uint64_t a) {
        if (MillerTest(a * 2 + 1))
            count++;
        });

    std::cout &amp;lt;&amp;lt; "Exponent " &amp;lt;&amp;lt; exponent &amp;lt;&amp;lt; " " &amp;lt;&amp;lt; x * 2 &amp;lt;&amp;lt; " Result " &amp;lt;&amp;lt; count + 1 &amp;lt;&amp;lt; " Expected " &amp;lt;&amp;lt; pp[exponent - 1] &amp;lt;&amp;lt; " " &amp;lt;&amp;lt; time(0) - t1 &amp;lt;&amp;lt; " seconds." &amp;lt;&amp;lt; std::endl;
}

int main()
{
    //CountPrimes(512);

    //2^32 is max value that can be tested
    CountPrimesParallel(32);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cpp</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Prime Number Generation Part 1: Optimized Trial Division With AVX512 SIMD Intrinsics.</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Tue, 08 Mar 2022 01:57:45 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/avx512-simd-intrinsic-prime-number-generator-in-c-i1d</link>
      <guid>https://dev.to/antidisestablishmentarianism/avx512-simd-intrinsic-prime-number-generator-in-c-i1d</guid>
      <description>&lt;p&gt;Overly commented...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;fstream&amp;gt;
#include &amp;lt;immintrin.h&amp;gt;

//number of primes up to exponents of 2, unused but included for reference.
int expected[] = { 1, 2, 4, 6, 11, 18, 31, 54, 97, 172, 309, 564, 1028, 1900, 3512, 6542, 12251, 23000, 43390, 82025,
155611, 295947, 564163, 1077871, 2063689, 3957809, 7603553, 14630843, 28192750, 54400028, 105097565, 203280221 };

// Returns # of primes up to limit and optionally saves them to a file. Limit must be an integer below 4294967295 (UINT32_MAX) and greater than 1;
static int Primes(uint32_t limit, bool save = false)
{
    if (limit &amp;lt; 2)
        throw std::invalid_argument("Limit must be greater than 1.");

    uint32_t total = 0;

    // Allocate memory for expected # of primes. Formula from Pierre Dusart.
    int end = (int)(limit / log(limit) * (1 + 1.2762 / log(limit)));

    // Also ensure prime array length is rounded up to a multiple of 16 and add 1 (since we are starting at primes[1]) to avoid errors when loading vector.
    end = ((end + 15) &amp;amp; ~15) + 1;

    uint32_t* primes = new uint32_t[end];

    // Fill expected array maximum integer value. Needed for one of the conditions for stopping the trial division loop.
    std::fill(primes, primes + end, UINT32_MAX);

    // Seed prime array with first two primes
    primes[0] = 2;
    primes[1] = 3;

    //Create vector of all zeros to compare remainders with.
    __m512i ZeroVector = _mm512_setzero_si512();

    for (uint32_t index = 3; index &amp;lt;= limit; index += 2)
    {
        __mmask16 p = 0;

        // Trial division only requires testing for divisors up to the square root of a number 
        uint32_t sq = sqrt(index);

        // Start pointer at prime number 3 (x[1]) since for loop only iterates over odd numbers.
        uint32_t* x = primes + 1;

        // Create vector filled with contents of current current index.
        __m512i VectorOfIndex = _mm512_set1_epi32(index);

        // Check for remainders (mod) from 16 primes in parallel for each loop iteration.
        while (x[0] != UINT32_MAX &amp;amp;&amp;amp; x[0] &amp;lt;= sq &amp;amp;&amp;amp; !(p = _mm512_cmpeq_epi32_mask(_mm512_rem_epu32(VectorOfIndex, _mm512_loadu_epi32((__m512i*)x)), ZeroVector)))
            x += 16;

        // If number is prime add it to our prime array to compute further primes.
        if (!p)
        {
            total++;
            primes[total] = index;
        }
    }

    if (save)
    {
        std::ofstream myfile("primes.txt");

        for (int count = 0; count &amp;lt;= total; count++)
            myfile &amp;lt;&amp;lt; primes[count] &amp;lt;&amp;lt; " ";

        myfile.close();
    }

    delete[] primes;
    return total + 1;
}

int main()
{
    time_t t1 = time(0);
    uint32_t limit = UINT32_MAX - 1;     //Upper lmit is UINT32_MAX - 1.

    try
    {
        int total = Primes(limit, false);

        std::cout &amp;lt;&amp;lt; "There are " &amp;lt;&amp;lt; total &amp;lt;&amp;lt; " primes less than or equal to " &amp;lt;&amp;lt; limit &amp;lt;&amp;lt; "." &amp;lt;&amp;lt; std::endl;
        std::cout &amp;lt;&amp;lt; "Computation completed in " &amp;lt;&amp;lt; time(0) - t1 &amp;lt;&amp;lt; " seconds." &amp;lt;&amp;lt; std::endl;
    }
    catch (std::invalid_argument&amp;amp; e)
    {
        std::cerr &amp;lt;&amp;lt; e.what() &amp;lt;&amp;lt; std::endl;
        return -1;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Incidentally, using _mm512_setzero_si512() in the loop instead of a static vector set to all zeros produces no performance penalty in my benchmarks (Compiler optimization?).&lt;/p&gt;

&lt;p&gt;Here is a more concise version of the Primes function if you prefer shorter code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static int Primes2(uint32_t limit)
{
    int end = ((int)(limit / log(limit) * (1 + 1.2762 / log(limit))) + 15) &amp;amp; ~15;
    uint32_t total = 1, * primes = new uint32_t[end];
    std::fill(primes, primes + end - 1, UINT32_MAX);
    primes[0] = 3;

    for (uint32_t index = 3; index &amp;lt;= limit; index += 2)
    {
        __mmask16 p = 0;
        uint32_t sq = sqrt(index), * x = primes;

        while (x[0] != UINT32_MAX &amp;amp;&amp;amp; x[0] &amp;lt;= sq &amp;amp;&amp;amp; !(p = _mm512_cmpeq_epi32_mask(_mm512_rem_epu32(_mm512_set1_epi32(index), _mm512_loadu_epi32((__m512i*)x)), _mm512_setzero_si512())))
            x += 16;

        if (!p)
        {
            total++;
            primes[total] = index;
        }
    }

    delete[] primes;
    return total;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cpp</category>
      <category>simd</category>
      <category>intrinsics</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>C# SIMD byte array compare</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Wed, 22 Sep 2021 07:54:25 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/c-simd-byte-array-compare-52p6</link>
      <guid>https://dev.to/antidisestablishmentarianism/c-simd-byte-array-compare-52p6</guid>
      <description>&lt;p&gt;My byte array compare that I recently posted on stackoverflow.&lt;br&gt;
&lt;a href="https://stackoverflow.com/a/69280107/13843929"&gt;https://stackoverflow.com/a/69280107/13843929&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Quoting my own post on stackoverflow...&lt;br&gt;
"This is similar to others, but the difference here is that there is no falling through to the next highest number of bytes I can check at once, e.g. if I have 63 bytes (in my SIMD example) I can check the equality of the first 32 bytes, and then the last 32 bytes, which is faster than checking 32 bytes, 16 bytes, 8 bytes, and so on. The first check you enter is the only check you will need to compare all of the bytes."&lt;/p&gt;

&lt;p&gt;It is the fastest performer in my tests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System.Runtime.Intrinsics.X86;

internal class Program
{
    public unsafe bool SIMDNoFallThrough(byte[] arr1, byte[] arr2)
    {
        if (arr1 == null || arr2 == null)
            return false;

        int arr1length = arr1.Length;

        if (arr1length != arr2.Length)
            return false;

        fixed (byte* b00 = arr1, b01 = arr2)
        {
            byte* b0 = b00, b1 = b01, last0 = b0 + arr1length, last1 = b1 + arr1length, last32 = last0 - 31;

            if (arr1length &amp;gt; 31)
            {
                while (b0 &amp;lt; last32)
                {
                    if (Avx2.MoveMask(Avx2.CompareEqual(Avx.LoadVector256(b0), Avx.LoadVector256(b1))) != -1)
                        return false;
                    b0 += 32;
                    b1 += 32;
                }
                return Avx2.MoveMask(Avx2.CompareEqual(Avx.LoadVector256(last0 - 32), Avx.LoadVector256(last1 - 32))) == -1;
            }

            if (arr1length &amp;gt; 15)
            {
                if (Sse2.MoveMask(Sse2.CompareEqual(Sse2.LoadVector128(b0), Sse2.LoadVector128(b1))) != 65535)
                    return false;
                return Sse2.MoveMask(Sse2.CompareEqual(Sse2.LoadVector128(last0 - 16), Sse2.LoadVector128(last1 - 16))) == 65535;
            }

            if (arr1length &amp;gt; 7)
            {
                if (*(ulong*)b0 != *(ulong*)b1)
                    return false;
                return *(ulong*)(last0 - 8) == *(ulong*)(last1 - 8);
            }

            if (arr1length &amp;gt; 3)
            {
                if (*(uint*)b0 != *(uint*)b1)
                    return false;
                return *(uint*)(last0 - 4) == *(uint*)(last1 - 4);
            }

            if (arr1length &amp;gt; 1)
            {
                if (*(ushort*)b0 != *(ushort*)b1)
                    return false;
                return *(ushort*)(last0 - 2) == *(ushort*)(last1 - 2);
            }

            return *b0 == *b1;
        }
    }

    static void Main(string[] args)
    {
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>csharp</category>
    </item>
    <item>
      <title>Windows Mobile Hotspot</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Tue, 26 Jan 2021 17:06:19 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/windows-mobile-hotspot-5aih</link>
      <guid>https://dev.to/antidisestablishmentarianism/windows-mobile-hotspot-5aih</guid>
      <description>&lt;p&gt;If you use Windows Mobile Hotspot and want to make some changes that aren't in the interface, then you might find this post interesting.&lt;/p&gt;

&lt;p&gt;All of these answers were discovered by me with a combination of Sysinternals procmon and C# code I have written and exist nowhere else on the net other than in this post and the superuser forums that I answered these questions.&lt;/p&gt;

&lt;p&gt;I hope this information will be of use to someone.&lt;/p&gt;

&lt;p&gt;Random Quizling:&lt;br&gt;
I try to use Windows Mobile hotspot to connect technical device with my notebook. It's working, but only if the notebook has connection to Internet. I need to use this configuration without Internet too. Is it possible somehow to start Windows Mobile hotspot without Internet or having created Microsoft Virtual Loopback adapter?&lt;/p&gt;

&lt;p&gt;ME:&lt;br&gt;
Yes, you can...&lt;/p&gt;

&lt;p&gt;First create your loopback adapter. You can create a loopback adapter by opening device manager, click on your computer name at the top of the list, then go to action menu/add legacy hardware. From there click next, then Install the hardware that I manually select from a list, then select Network Adapters, then next, then select Microsoft on the left and Microsoft KM-TEST Loopback Adapter on the right, then next and next again.&lt;/p&gt;

&lt;p&gt;Go to Control Panel/Network and Internet/Network and Sharing Center/Change adapter settings. Right click on network adapter you just created and rename it to Loopback.&lt;/p&gt;

&lt;p&gt;Then you can run this PowerShell script to start the hotspot bound to the loopback adapter.&lt;/p&gt;

&lt;p&gt;$profile = [Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime]::GetConnectionProfiles()  | where {$_.profilename -eq "loopback"}&lt;/p&gt;

&lt;p&gt;$tether = [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]::CreateFromConnectionProfile($profile)&lt;/p&gt;

&lt;p&gt;$tether.StartTetheringAsync()&lt;/p&gt;

&lt;p&gt;You can make other changes by going to Mobile Hotspot in Settings, e.g. turn off power saving so the hotspot doesn't automatically disable itself if no client is connected.&lt;/p&gt;

&lt;p&gt;Your hotspot(host) will have the IP address 192.168.137.1 and you will be able to access it by computer name if you make the firewall changes below.&lt;/p&gt;

&lt;p&gt;All firewall rules still apply to this network, so access to your computer will be in the PUBLIC network. I have set the loopback adapter to private, and it works, but for some reason it always eventually sets itself back to public, presumably because the network can't be identified.&lt;/p&gt;

&lt;p&gt;To access shares on the host: Go to Control Panel/Network and Internet/Network and Sharing Center/select change advanced sharing settings on the left, then click Guest or Public and Turn on network discovery and turn on file and printer sharing.&lt;/p&gt;

&lt;p&gt;Another random Quizling:&lt;br&gt;
I am trying to connect my tablet directly to my laptop for better performance in in-home streaming (Steam Link iOS app). However, when both the laptops's connection to the internet and its hotspot use the builtin Wifi hardware, I am experiencing significant stuttering. In terms of a ping from tablet to laptop I am seeing lost packages and latency spikes.&lt;/p&gt;

&lt;p&gt;After connecting a USB Wifi adapter I have noticed, that Windows 10 will still use the builtin wifi hardware for creating the hotspot.&lt;/p&gt;

&lt;p&gt;Is it possible to tell Windows 10 to use the builtin Wifi adapter for connecting to the internet, and the USB-adapter for providing the hotspot?&lt;/p&gt;

&lt;p&gt;Workaround (limited/inconvenient)&lt;br&gt;
Since posting the question I found, that I can work around the problem by connecting the USB Wifi-Adapter to the home-wifi. Enabling mobile hotspot then (presumably) uses the built-in wifi adapter, allowing the following topology:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         &amp;lt;poorly drawn text image omitted&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It isn't a full solution however, as I can attach a more powerful antenna to the USB-Adapter, but not to the built-in adapter, for streaming across room boundaries. Additionally, when pluggin in the USB adapter this way instead of only enabling the hotspot, more steps are needed:&lt;/p&gt;

&lt;p&gt;Disable the connection of the builtin-adapter to the Home wifi&lt;br&gt;
Enable connection of the USB Adapter to the Home wifi&lt;br&gt;
Enable mobile hotspot.&lt;/p&gt;

&lt;p&gt;Me:&lt;br&gt;
Yes, you can select which interface the mobile hotspot is using if you are willing to edit the registry.&lt;/p&gt;

&lt;p&gt;The key you need to modify is HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\icssvc\Settings\PreferredPublicInterface.&lt;/p&gt;

&lt;p&gt;Make sure the hotspot is off before you make a change.&lt;/p&gt;

&lt;p&gt;The binary data in this key is the ID of the adapter you want to use. You can get the adapter id with:&lt;/p&gt;

&lt;p&gt;wmic nicconfig get description,settingid&lt;/p&gt;

&lt;p&gt;To make it easier you should export the registry key (and make a copy) and change the current PreferredPublicInterface with your new one and then import it back into the registry.&lt;/p&gt;

&lt;p&gt;Each section between the dashes of the id has its bytes reversed in the binary key, e.g. if the Id of the interface you want to select for Windows to use as the adapter for the Mobile Hotspot is:&lt;/p&gt;

&lt;p&gt;01020304-0506-0708-0910-111213141516&lt;/p&gt;

&lt;p&gt;then the data you would put in the key would be:&lt;/p&gt;

&lt;p&gt;04 03 02 01 06 05 08 07 10 09 16 15 14 13 12 11&lt;/p&gt;

&lt;p&gt;or in the registry file:&lt;/p&gt;

&lt;p&gt;"PreferredPublicInterface"=hex:04,03,02,01,06,05,08,07,10,09,1,15,14,13,12,11&lt;/p&gt;

&lt;p&gt;Tested on my computer, works without issue.&lt;/p&gt;

&lt;p&gt;Yet another random Quizling:&lt;br&gt;
How do I increase the maximum number of connected devices from eight to twenty?&lt;/p&gt;

&lt;p&gt;Me:&lt;br&gt;
If you add a Dword value named WifiMaxPeers to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\icssvc\Settings it will change what the upper limit in Mobile Hotspot.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>mobilehotspot</category>
      <category>hotpsot</category>
    </item>
    <item>
      <title>Microsoft error lookup tool</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Tue, 07 Jul 2020 10:59:18 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/microsoft-error-lookup-tool-4418</link>
      <guid>https://dev.to/antidisestablishmentarianism/microsoft-error-lookup-tool-4418</guid>
      <description>&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/windows/win32/debug/system-error-code-lookup-tool"&gt;https://docs.microsoft.com/en-us/windows/win32/debug/system-error-code-lookup-tool&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A small command line utility to look up those pesky error codes.&lt;/p&gt;

&lt;p&gt;The amount of time and aggravation this tool saves me is beyond words.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>PowerShell script to download all AppX files and their dependencies for currently installed packages.</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Fri, 03 Jul 2020 18:37:00 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/powershell-script-to-download-appx-files-from-the-microsoft-store-for-currently-installed-packages-501e</link>
      <guid>https://dev.to/antidisestablishmentarianism/powershell-script-to-download-appx-files-from-the-microsoft-store-for-currently-installed-packages-501e</guid>
      <description>&lt;h6&gt;
  
  
  #Script to download Appx/AppxBundle/MSIX files for all packages and their dependencies currently installed on your computer.
&lt;/h6&gt;

&lt;p&gt;I have successfully ran this version on several machines and EVERY dependency does get downloaded and copied.&lt;/p&gt;

&lt;p&gt;This script must be run as an administrator.&lt;/p&gt;

&lt;p&gt;Resulting packages are in c:\appx_install.&lt;/p&gt;

&lt;p&gt;Cached packages are stored in C:\Windows\SoftwareDistribution\Download (which you may want to manually empty after running this script).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
   Write-Warning "This script must be run as an Administrator"
   Break
}

Clear-Host

#######Function to enumerate bundled packages and copy bundled packages/dependencies to c:\appx_install.
function Copy-Bundled ($up, $root) {
   $count = $up.count
   For ($i = 0; $i -lt $count; $i++) {
      $folder = ("$root\$($up.item($i).title)") -replace "\.", "_"
      if (!(Test-Path $folder -PathType Container)) {
         $ftemp = New-Item -ItemType Directory -Force $folder
      }
      try {
         write-host "Copying files to $folder"
         $up.item($i).CopyFromCache($folder, $False)
      }
      catch {
         if ($_ -like "*0x80246010*") {
            write-host "`n$folder with identity $($up.item($i).Identity.updateid) does not exist. Will try to download...."
            download-updates $up
            $up.item($i).CopyFromCache($folder, $False)
            if ($?) {
               write-host "`nCopy successfull`n"
            }
         }
         elseif (!($_ -like "*0x80070050*")) {                                #Ignore "The file exists." errors so that script can be run repeatedly without having to remove resulting files from c:\appx_install.
            write-host "`n $_ `n"
         }
      }
      if (($up.item($i).bundledupdates.count)) {
         Copy-Bundled $up.item($i).bundledupdates $root
      }
   }
}

#######Function to enumerate downloaded packages.
Function Copy-Updates ($up, $root) {
   $count = $up.count
   For ($i = 0; $i -lt $count; $i++) {
      $folder = ("$root\$($up.item($i).title)") -replace "\.", "_"
      if (!(Test-Path $folder -PathType Container)) {
         $ftemp = New-Item -ItemType Directory -Force $folder
      }
      Copy-Bundled $up.item($i).bundledupdates $folder
   }
}

Function Download-Updates ($updates) {
   $UpdatesToDownload = New-Object -Com Microsoft.Update.UpdateColl
   For ($i = 0; $i -lt $updates.count; $i++) {
      $UpdatesToDownload.Add($updates.item($i)) | out-null
   }
   $Downloader = (New-Object -Com Microsoft.Update.Session).CreateUpdateDownloader()
   $Downloader.IsForced = $True                                               #Forces the downloader to download packages that are already installed. https://docs.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatedownloader?redirectedfrom=MSDN
   $Downloader.Updates = $UpdatesToDownload
   $Downloader.Download() | Out-Null
   Write-Host "`nDownload Finished.`n"
}

Function Find-Updates {
   $Session = New-Object -ComObject Microsoft.Update.Session
   $Searcher = $Session.CreateUpdateSearcher()
   $Searcher.ServiceID = '855e8a7c-ecb4-4ca3-b045-1dfa50104289'                #Microsoft Store Service ID.
   $Searcher.SearchScope = 2                                                   #https://docs.microsoft.com/en-us/windows/win32/api/wuapi/ne-wuapi-searchscope
   $Searcher.ServerSelection = 3                                               #https://docs.microsoft.com/en-us/previous-versions/windows/desktop/aa387280(v=vs.85)
   $Searcher.Online = $False                                                   #Changing this to $True will not only result in no downloads, but changing it back to false (even with a reboot) will not rectify the situation immediately (however, *eventually* the situation resolves itself).
   $Criteria = "IsInstalled = 1"                                               #https://docs.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatesearcher-search
   Write-Host "`nEnumerating main package list....`n"
   $SearchResult = $Searcher.Search($Criteria)
   $Updates = ($SearchResult.Updates)
   Write-Host "`n$($updates.count) packages found.`n"
   $Updates
}

#######Main

$updates = Find-Updates
Write-Output "`nDownloading currently installed software packages and dependencies. This may take a while...`n"
Download-updates $Updates

Write-Output "`nCopying packages and dependencies to c:\appx_install...`n"
if (!(Test-Path "c:\appx_install" -PathType Container)) { New-Item -ItemType Directory -Force "c:\appx_install\" | Out-Null }
Copy-Updates $updates "c:\appx_install"

Write-Output "`nScript completed. Your downloaded files are located in c:\appx_install."
Write-Output "Files that do not have an extension can be renamed to .appx (or any other extension that the app installer supports. No renaming necessary to install with PowerShell."

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>powershell</category>
    </item>
    <item>
      <title>Search Microsoft Store from PowerShell</title>
      <dc:creator>Antidisestablishmentarianism</dc:creator>
      <pubDate>Fri, 03 Jul 2020 14:39:03 +0000</pubDate>
      <link>https://dev.to/antidisestablishmentarianism/search-microsoft-store-from-powershell-2bjj</link>
      <guid>https://dev.to/antidisestablishmentarianism/search-microsoft-store-from-powershell-2bjj</guid>
      <description>&lt;p&gt;This is an old version, I can't find the latest one I wrote before I moved on to other things...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bwle-NW---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0donzode9bxswplmrxt0.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bwle-NW---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0donzode9bxswplmrxt0.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Leaving out deviceFamilyVersion and userSegments.&lt;br&gt;
I believe device family version tells the site what category of content to search, e.g. kids, adults, and i'm not sure what usersegments does, i think it might be unique to each user but both are not mandatory parameters.&lt;br&gt;
oemid and scmid, while not mandatory are important if you want to search for apps that are only for your make of computer, e.g. you will not see the lenovo vantage program in a search if you don't inlclude those fields.&lt;/p&gt;

&lt;p&gt;Function Search-MSStore ($query) {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$base = "https://storeedgefd.dsx.mp.microsoft.com/v8.0/search?"; $market = "US"; $locale = "en-US"

$paramstring = [ordered]@{
market = "US"
locale = "en-US"
query = "microsoft"
mediaType = "apps"
category = "all"
moId = "Public"
oemId = "LENOVO"
scmId="Lenovo3_Idea"
deviceFamily="windows.desktop"
appVersion="12006.1001.0.0"
catalogLocales="en-US"
availableOn="windows.desktop"
maturityRating="all"
cardsEnabled="true"
pzn="0"
pageSize="25"
skipItems="0"}

$paramobject = New-Object -TypeName PSObject
$paramobject | Add-Member -NotePropertyMembers $paramstring
$paramobject.query=$query

[string]$param = (-join ($paramobject.psobject.Properties.name | foreach {$_ + "=" + $paramobject.$_ + "&amp;amp;"})).trimend("&amp;amp;")

$response = Invoke-WebRequest -UseBasicParsing -Uri ($base+$param)
$cards = ($response.content | ConvertFrom-Json -ashashtable).Payload.Cards
$cards | select Title,Price,ProductId
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

</description>
      <category>powershell</category>
    </item>
  </channel>
</rss>
