Friday, May 31, 2019

C-Sharp : A better Substring extension for common uses

Here's a better Substring extension for common use patterns.

The aim here is get rid of nasty length calculation, which to me in the original method (see below) is counter intuitive. IMHO the 2nd argument should have been endIndex

public string Substring (int startIndex, int length);
Therefore, my Substring extension method gets rid of length calculations altogether.

public string Substring (string findString, enum First/LastPosition, enum CommonStringAction);

Instead you just supply the string you want to find (needle) in the search string (haystack) and supply it with a common action. 





Source Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;

public static class Program
{
     /// <summary>
        /// Define common patterns for substring actions
        /// </summary>
        public enum StrCut
        {
            BeforeLessStr = 0,
            BeforeInclStr = 1,
            AfterLessStr = 2,
            AfterInclStr = 4
        }
        /// <summary>
        /// Cut from front or back
        /// </summary>
        public enum StrCutLoc
        {
            First = 0,
            Last = 1
        }
        /// <summary>
        /// Extend Susbstring with ability to pass a string and choose common actions surrounding that string.
        /// </summary>
        /// <param name="s">haystack</param>
        /// <param name="arg">needle</param>
        /// <param name="l">search location</param>
        /// <param name="e">include needle</param>
        /// <returns></returns>
        /// <author>//Fri 31-May-19 12:45pm metadataconsult@gmail.com</author>
        public static string Substring(this string s, string arg, StrCutLoc l, StrCut e)
        {
            //Range checking, why do you neet a unit test
            if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(arg)) return string.Empty;
            if (arg.Length > s.Length) return string.Empty;

            int idxarg = -1; 

            if (l.Equals(StrCutLoc.First))
                idxarg = s.IndexOf(arg);
            else if (l.Equals(StrCutLoc.Last))
                idxarg = s.LastIndexOf(arg);
       
            if (idxarg == -1) return string.Empty; //is arg found in string

            bool argfits = (idxarg + arg.Length) <= s.Length; //is arg within limit of end of string
            
            if (e.Equals(StrCut.BeforeLessStr))
            {
                s = s.Substring(0, idxarg);
            }
            else if (argfits && e.Equals(StrCut.BeforeInclStr))
            {
                s = s.Substring(0, (idxarg + arg.Length));
            }
            else if (argfits && e.Equals(StrCut.AfterLessStr))
            {
                s = s.Substring(idxarg + arg.Length);
            }
            else if (e.Equals(StrCut.AfterInclStr))
            {
                s = s.Substring(idxarg);
            }
            return s;
        }
 
 public static void Main()
 {
  string text = "{\"InsertSymbolText\",\"InsertSymbol\"},";  
  string cut = ",";
 
  Console.WriteLine("text = "+ text); 
  Console.WriteLine();
  Console.WriteLine("Let's get rid of length param, like this Substring(2,2) = " + text.Substring(2,2)); 
  Console.WriteLine();
 
  Console.WriteLine("BEGIN - Most of time, I just want to get a supply a string a work around it"); 
  
  Console.WriteLine("AfterLessStr = " + text.Substring(cut, StrCutLoc.First, StrCut.AfterLessStr));
  Console.WriteLine("AfterInclStr = " + text.Substring(cut, StrCutLoc.First, StrCut.AfterInclStr));
  Console.WriteLine("BeforeInclStr = " + text.Substring(cut, StrCutLoc.Last, StrCut.BeforeInclStr));
  Console.WriteLine("BeforeLessStr = " + text.Substring(cut, StrCutLoc.Last, StrCut.BeforeLessStr));
  Console.WriteLine("END");
 }
}

Monday, May 27, 2019

Windows Subsystem Layer 2 does not work with VMWare or Virtual Box

What is Windows Subsystem Layer 2 ?





Will I be able to run WSL 2 and other 3rd party virtualization tools such as VMware, or Virtual Box? NO

Some 3rd party applications cannot work when Hyper-V is in use, which means they will not be able to run when WSL 2 is enabled. Unfortunately, this does include VMware, and versions of Virtual Box before Virtual Box 6 (Virtual Box 6.0.0 released in December 2018 now supports Hyper-V as a fallback execution core on a Windows host!)
We are investigating ways to help resolve this issue. For example, we expose a set of APIs called Hypervisor Platform that third-party virtualization providers can use to make their software compatible with Hyper-V’s. This lets applications use the Hyper-V architecture for their emulation such as the Google Android Emulator, and Virtual Box 6 and above which are both now compatible with Hyper-V.

https://devblogs.microsoft.com/commandline/wsl-2-post-build-faq/


WSL 2 Linux Kernel will be updated by Windows Update

That's right the Linux 4.19 will be fully CVE updated and managed by Windows Update.

Friday, May 24, 2019

Phishing Email - Re : (New Report Linked) Summary User - Confirmation change password your account on

For the record, this is an Apple phishing email attempt that is recently going around and got caught in spam filters. 


From :"noreplay@apple.com"
  Subject :Re : (New Report Linked) Summary User - Confirmation change
 password your account on 5/24/2019 11:11:11 AM / Resumen de control de usuario


Contains a .dot attachment (which contains malware)



SPAM/ PHISHING LINKs;  



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 apple.com site then forget it.

  3. The best way is to look at message source, see below.

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 (downarrow to top right)->Report Phishing 

Report Phishing URLs at Google now 

If you have recieved this email take further action now by click these links

  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

Monday, May 20, 2019

Phishing Email - Netflix Auto Subscribe cannot be renewed

For the record, this is a Netflix phishing email attempt that is recently going around and made it through spam filters. What to do?  Report them, goto bottom of page.


From :noreply@netflix.com <noreply-06990010.05@mentalcengeng.com>
 
Subject
 :
Re: Statement - The Auto Subscribe Cannot be Renew At-May 18 2019 [E6ILS]


SPAM/ PHISHING LINKs;  



Here's  a preview of spam link from Korea


But don't be fooled, this page could infect your machine



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 apple.com site then forget it.

  3. The best way is to look at message source, see below.

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 (downarrow to top right)->Report Phishing 

Report Phishing URLs at Google now 

If you have recieved this email take further action now by click these links

  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

Saturday, May 18, 2019

Get BING's search algorithm for free

Microsoft has made one of the most advanced AI tools it uses to better meet people’s evolving search needs available to anyone as an open source project on GitHub. On Wednesday, it also released user example techniques and an accompanying video for those tools via Microsoft’s AI lab.

Microsoft uses vector search for its own Bing search engine, and the technology is helping Bing better understand the intent behind billions of web searches and find the most relevant result among billions of web pages.
The algorithm, called Space Partition Tree And Graph (SPTAG), allows users to take advantage of the intelligence from deep learning models to search through billions of pieces of information, called vectors, in milliseconds. That, in turn, means they can more quickly deliver more relevant results to users.
































Vector search makes it easier to search by concept rather than keyword. For example, if a user types in “How tall is the tower in Paris?” Bing can return a natural language result telling the user the Eiffel Tower is 1,063 feet, even though the word “Eiffel” never appeared in the search query and the word “tall” never appears in the result.

“Bing processes billions of documents every day, and the idea now is that we can represent these entries as vectors and search through this giant index of 100 billion-plus vectors to find the most related results in 5 milliseconds,” said Jeffrey Zhu, program manager on Microsoft’s Bing team.
To put that in perspective, Majumder said, consider this: A stack of 150 billion business cards would stretch from here to the moon. Within a blink of an eye, Bing’s search using SPTAG can find 10 different business cards one after another within that stack of cards.



Friday, May 17, 2019

Microsoft's new command line app for Windows Terminal

As of May 6th, 2019, after 30 years, Windows console (cmd.exe) has got a reboot. The new  Windows Terminal and Windows Console have been made open source and you can clone, build, run, and test the code from the repository on 
GitHub: https://github.com/Microsoft/Terminal

This is early stages so you have to build the exe.

For example, this is how the command line is consumed - you can change that now
https://github.com/microsoft/terminal/blob/master/src/host/ConsoleArguments.cpp


Official Microsoft Blog release
https://devblogs.microsoft.com/commandline/introducing-windows-terminal/








Thursday, May 9, 2019

C-Sharp : A better Substring extension method to get a string within a string

Here's a Substring extension when you want to get a string within a string.

The aim here is get rid of nasty length calculation, which to me in the original method (see below) is counter intuitive. IMHO the 2nd argument should have been endIndex

public string Substring (int startIndex, int length);

Therefore, my Substring extension method gets rid of length calculations altogether.

public string Substring (string findString, enum CommonStringAction);
Instead you just supply the string you want to find (needle) in the search string (haystack) and supply it with a common action. 


Source Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;

public static class Program
{
  /// <summary>
        /// Define common patterns for substing actions
        /// </summary>
        public enum StrCut
        {
            BeforeLessStr = 0,
            BeforeInclStr = 1,
            AfterLessStr = 2,
            AfterInclStr = 4
        }
        /// <summary>
        /// Extend Susbstring with ability to pass a string and choose common actions surrounding that string.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="arg">string argument</param>
        /// <param name="e">enum</param>
        /// <returns></returns>
        /// <author>Wed 01-May-19 - metadataconsult@gmail.com</author>
        public static string Substring(this string s, string arg, StrCut e)
        {
            //Range checking, why do you neet a unit test
            if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(arg)) return string.Empty;
            if (arg.Length > s.Length) return string.Empty;

            int idxarg = s.IndexOf(arg);

            if (idxarg == -1) return string.Empty; //is arg found in string

            bool argfits = (idxarg + arg.Length) <= s.Length; //is arg within limit of end of string
            
            if (e.Equals(StrCut.BeforeLessStr))
            {
                s = s.Substring(0, idxarg);
            }
            else if (argfits && e.Equals(StrCut.BeforeInclStr))
            {
                s = s.Substring(0, (idxarg + arg.Length));
            }
            else if (argfits && e.Equals(StrCut.AfterLessStr))
            {
                s = s.Substring(idxarg + arg.Length);
            }
            else if (e.Equals(StrCut.AfterInclStr))
            {
                s = s.Substring(idxarg);
            }
            return s;
        }
 
 public static void Main()
 {
  string SourceURL = "SourceURL:https://metadataconsulting.blogspot.com/2019/04/Using-HTACG-HTML-Tidy-official-release-binaries-for-TidyHTML5Mananged.html"; 
  //string SURL = "SourceURL:";
  //string SURL = "SourceURL:https://metadataconsulting.blogspot.com/2019/04/Using-HTACG-HTML-Tidy-official-release-binaries-for-TidyHTML5Mananged.html"; 
  string SURL = ".html";
  Console.WriteLine("Let's get rid of length param, like this Substring(0) = " + SourceURL.Substring(0)); 
    
  Console.WriteLine("BEGIN - Most of time, I just want to get a supply a string a work around it"); 
  Console.WriteLine("org = "+ SourceURL); 
  Console.WriteLine("AfterLessStr = " + SourceURL.Substring(SURL,StrCut.AfterLessStr));
  Console.WriteLine("AfterInclStr = " + SourceURL.Substring(SURL,StrCut.AfterInclStr));
  Console.WriteLine("BeforeInclStr = " + SourceURL.Substring(SURL,StrCut.BeforeInclStr));
  Console.WriteLine("BeforeLessStr = " + SourceURL.Substring(SURL,StrCut.BeforeLessStr));
  Console.WriteLine("END");
 }
}

Thursday, May 2, 2019

Windows 7 End-of-Life Support Notice Pop-up



😩 Win7 death is coming ðŸ˜©

All good things must come to an end, even Windows 7. After January 14, 2020, Microsoft will no longer provide security updates or support for PCs running Windows 7. But you can keep the good times rolling by moving to Windows 10.

For users of Windows 7 Professional and Windows 7 Enterprise, you can purchase Extended Security Updates through January 2023. For an in-depth FAQ about Windows 7 Extended Security Updates, please download the Microsoft End of Support FAQ.