Thursday, February 25, 2021

The most important URL for a .NET developer

Get source implementation code of the entire .NET Framework. See how the experts code at Microsoft. 

Below URL is base code for Arrays implementation in .NET Framework.

https://referencesource.microsoft.com/#mscorlib/system/array.cs,42e9b7616956cf94

and looks like



I wrote this post because I keep on forgetting about this resource. You can download all documentation starting from Framework 4.5.1. 

Thursday, February 18, 2021

Home Depot phishing email with subject Re: Open Immediately

For the record, this is an Home Depot phishing email attempt that is recently going around, with subject "Re: Open Immediately"

What to do?  Report them, goto bottom of page. 


From : Home Depot Survey <infogxxxxxxxxxxxxxx@xxxxxxxxxxxxgmail.mcsv.net>
Subject : 
Re: Open Immediately


CONGRATULTIONS, You've Been Chosen - Confirm Now !!





PHISHING LINKs;

1. https://justurl.in/pKMGea expands to http://1365abd.net/r.php?xxxx

How to tell this is a Phishing email ?

  1. Check email address in full, if it's not from originating company then it's phishing.
  2. Hover over all links in email, if it's not from the  company's website then forget it.
  3. The best way is to 

How to examine Email Message Source ?

Now lets look at message source
  1. Outlook.com->Actions->View Message Source. 
  2. Gmail.com->More (down arrow to top right)->Show original.
Check for suspicious links, anything that does not originate from apple.com.


Report Phishing Email (not as Spam)

  1. Outlook.com->Junk (at Top)->Phishing Scam
  2. Gmail.com->More (down-arrow to top right)->Report Phishing 

Report Phishing

If you have received this email take further 

  1. https://www.google.com/safebrowsing/report_phish/


Report phishing at Microsoft and government agencies

  1. http://www.microsoft.com/security/online-privacy/phishing-faq.aspx

Thursday, February 11, 2021

C# .NET Get difference between two unordered not unique lists using BitArrays for super fast speed


Here's how to get the difference between two lists preserving duplicates in each list that is super fast, using BitArrays. 

It's a counter intuitive approach since it loops over the lists 3 times, but since we are just setting a bit, it's super efficient. Definitely, interesting idea to use for other situations. 

As in my previous post, i dismiss all the Stack Overflow solutions with live code, and I presented my 1st attempt at the solution. 

This post demonstrates my super fast implementation, enjoy! 

//UNORDERED, NOT UNIQUE lists, lists with duplicates 

string[] arrA = new string[] { "1", "1", "2", "3", "4", "5", "9", "7", "7", "7" };
string[] arrB = new string[] { "1", "1", "2", "2", "3", "4", "5", "5", "5", "5" };

//DESIRED RESULT

2,5,5,5,7,7,7,9 OR 2,5,5,5,9,7,7,7 OR 9,7,7,7,2,5,5,5  //UNORDERED IS SUFFICIENT

NOTE: Linq Except but it's designed as a set command, and as a consequence it removes duplicates.

IEnumerable<string> AminuBdifference = arrA.Except(arrB); //removes dups
IEnumerable<string> BminuAdifference = arrB.Except(arrA); //remove dups

IEnumerable<string> Uniondifference = arrA.Union(arrb); //ideally, but no good because dups are removed

See https://dotnetfiddle.net/oHOms5  which demonstrates Linq Except use.


Below is my super fast implementation, using a pure BitArray implementations, enjoy!

 

Source Code
using System;
using System.Collections; 
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics; 

//CHALLENGE - Get difference between two unorderd, not unique lists, duplicates allowed within a list and across both lists.
//SOLUTION - https://metadataconsulting.blogspot.com/2021/02/CSharp-dotNet-Get-difference-between-two-unordered-not-unique-lists-aka-duplicates-allowed-within-a-list-and-across-both-lists.html
//OPTIMIZE - THIS IS IT using BitArray - https://metadataconsulting.blogspot.com/2021/02/CSharp-dotNet-Get-difference-between-two-unordered-not-unique-lists-lightning-fast-optimized.html
//OPTIMIZEv2 - All BitArray imp - https://metadataconsulting.blogspot.com/2021/02/CSharp-dotNet-Get-difference-between-two-unordered-not-unique-lists-using-BitArrays-for-super-fast-speed.html
                    
public class Program
{
    public static int loopcnt = 0;
    
    public static void Main()
    {
            Stopwatch sw = new Stopwatch();
            sw.Start(); 

            //RANDOM case - typical use
            string[] arrA = new string[] { "7", "1", "2", "3", "4", "5", "9", "7", "7", "1" };
            string[] arrB = new string[] { "1", "1", "2", "2", "3", "4", "5", "5", "5", "5" };

            //WANT           2,5,5,5,9,7,7,7

            //WORST case - entirely different, but have 1 value in common to make it interesting
            //string[] arrA = new string[] { "1", "1", "2", "3", "4", "5", "6", "7", "7", "7" };//1st list
            //string[] arrB = new string[] { "8", "9", "10", "12", "1", "14", "15", "15", "11", "9" };//2nd list

            //BEST case - identical
            //string[] arrA = new string[] { "1", "1", "2", "3", "4", "5", "6", "7", "7", "7" };//1st list
            //string[] arrB = new string[] { "1", "1", "2", "3", "4", "5", "6", "7", "7", "7" };//2nd list


            sw.Stop();
            Console.WriteLine("RANDOM CASE -two unorderd, not unique lists ");
            Console.WriteLine("A  = " + string.Join(",", arrA));
            Console.WriteLine("B  = " + string.Join(",", arrB));
            sw.Restart();

            string[] arrBminusA = new string[arrB.Length];
            string[] arrAminuB = new string[arrA.Length];   
            BitArray bitArrAminusB = new BitArray(arrA.Length);
            BitArray bitarrBminusA = new BitArray(arrB.Length);
            
            //May seem counter intuitive to run this over 3 loop but it's faster ~ 10 ticks
            int a = 0;
            for (int b = 0; b < arrB.Length; b++)
            {
                for (a = 0; a < arrA.Length; a++)
                {
                    loopcnt++;//not need for timing analysis 

                    if (!bitArrAminusB[a] && arrA[a] == arrB[b])
                    {
                        bitArrAminusB.Set(a, true); //A-B, list A difference/subtract of list B  
                        bitarrBminusA.Set(b, true); //B-A, list B difference/subtract of list A  
                        break;

                    }
                }
            }

            int idxa = 0;
            for (int aa = 0; aa < arrA.Length; aa++)
            {
                if (!bitArrAminusB[aa])
                    arrAminuB[idxa++] = arrA[aa];
                
            }

            
            int idxb = 0;
            for (int bb = 0; bb < arrB.Length; bb++)
            {
                if (!bitarrBminusA[bb])
                    arrBminusA[idxb++] = arrB[bb];

            }
            sw.Stop();

           Console.WriteLine("(A-B) Result = " + string.Join(",", arrAminuB).Trim(','));
           //Console.WriteLine("D  = " + string.Join(",", D));
           //Console.WriteLine("E  = " + string.Join(",", E)); 

           Console.WriteLine("(B-A) Result = " + string.Join(",", arrBminusA).TrimEnd(','));

           Console.WriteLine("No. of loops = " + loopcnt);
           Console.WriteLine("No. of loops = " + arrA.Length*2 + " - Post copy using BitArray to a sized array");

           //Un 
           Console.WriteLine("Result Unorderd Final A then B = " + (string.Join(",", arrAminuB)).Trim(',') + "," + string.Join(",", arrBminusA).Trim(',') + " in " + sw.ElapsedTicks + " ticks.");
           Console.WriteLine("Result Unorderd Final B then A = " + (string.Join(",",  arrBminusA)).Trim(',') + "," + string.Join(",",arrAminuB).Trim(',') + " in " + sw.ElapsedTicks + " ticks.");

           
           List<string> D = arrBminusA.ToList().Concat(arrAminuB.ToList()).ToList();
           D.Sort();

           Console.WriteLine("Result  Ordered Final = " + string.Join(",", D).TrimStart(','));
           Console.WriteLine("Result  O(n^2+2n) but very fast - can you beat it?"); 
    
    }
}