Wednesday, May 20, 2020

[SOLVED] You'll need a new app to open this windowsdefender link

Recently when I tried to access :Virus & threat protection" on my Windows 10 computer, I would get the following:



This was fixed by:
  1. Open Powershell in admin mode
  2. Execute: Add-AppxPackage -Register -DisableDevelopmentMode "C:\Windows\SystemApps\Microsoft.Windows.SecHealthUI_cw5n1h2txyewy\AppXManifest.xml"
  3. Reboot

Monday, May 11, 2020

Wired network missing on Ubuntu 20.04 with VMWare Workstation Pro 15

I don't think this really has to do with VMWare Workstation, but a fresh new Ubuntu 20.04 install was missing the wired network. This was fixed by:

Modify /etc/netplan/01-network-manager-all-yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: true


Execute cmds:
$ sudo netplan generate
$ sudo netplan apply
$ sudo service network-manager restart

Sunday, October 13, 2019

Powershell: Tail file

You can easily tail a file on Windows using PowerShell.

Get-Content myFileName -Wait

Wednesday, September 18, 2019

Visual Studio 2019 - Favorite Less-Known Keyboard Shortcuts

Some of the less well-known keyboard shortcuts in Visual Studio 2019 that I enjoy.

Ctrl Q => VS command search
Alt ~ => special context menu
Ctrl Shift V - clipboard history
Ctrl ; => search solution explorer
Ctrl Alt Click => set multi-caret edit locations
Ctrl Alt . => select next multi-caret edit location
Ctrl Alt ; => select all multi-caret edit locations
Ctrl Shift Backspace => go to last edit location
Ctrl - => go to last cursor location
Ctrl T => type r for recent files opened
Ctrl K Ctrl X => insert code snippet
Ctrl K Ctrl S => surround code with snippet
Shift Alt [ => go to containing block

There are many other ones demo'd in this Microsoft video.

Thursday, November 1, 2018

SQL Server: List all tables in a specific schema

SELECT * 
FROM sys.objects 
WHERE schema_id = SCHEMA_ID('schemaName') and type='U'


'U' stands for User table.

Wednesday, August 29, 2018

Windows Explorer: Search for files/folders with exact name only

Once and a while I want to search a directory structure and find all the files or folders that only match a specific name only.  Here is the quick way to do this in the Windows Explorer search box (Ctrl-E):

File
name:=seachName

Folder
kind:=folder name:=searchName


Thursday, February 22, 2018

Spectacularly simple and flexible jQuery drop-down plugin (Bootstrap 4)

Here is a very simple, yet flexible, custom drop-down selection control.  Very lightweight JavaScript and all the needed options.  You can also register to be notified of a selection and have it pass you a HTML "data-" tag value.  You'll need jQuery and Bootstrap.

Note: You write your use normal Bootstrap 4 drop-down menu code, then just create an instance of the plugin, and wah-lah!  Very nice.

Give it a whirl on on JsFiddle.



Tuesday, January 23, 2018

[Solved] Convert complex C#/JSON object to query string, ASPNET Core 2.0

I had to call an internal web page using HttpClient to get the HTML.  The Razor Page's OnGetAsync expected a C# complex object (nested types) as a parameter.  Here is a string extension, JsonAsQueryString, to convert a complex object into a query string for ASPNET Core 2.0.  I just converted the C# complex object to JSON using JsonConvert.Serialize, then use this extension method.

    public static class StringExtensions
    {
        public static string JsonAsQueryString(this string json)
        {
            return ParseJObject(json, string.Empty);
        }

        private static string ParseJObject(string json, string parentField = "")
        {
            var jo = (JObject)JsonConvert.DeserializeObject(json);
            var query = String.Join("&",
                jo.Children().Cast<JProperty>()
                .Select(jp => StringExtensions.ParseJProperty(jp, parentField)));

            return query;
        }

        private static string ParseJProperty(JProperty jp, string parentField)
        {
            var parentFormat = string.IsNullOrWhiteSpace(parentField) ? string.Empty : $"{parentField}.";

            if (jp.Value as JArray != null)
            {
                // this object is an array; repeat names
                var tokens = string.Join("&", jp.Value
                    .Select(t => $"{parentFormat}{jp.Name}={HttpUtility.UrlEncode(t.ToString())}"));

                return tokens;
            }
            else if (jp.Value.Type == JTokenType.Object)
            {
                // nested object; make a recursive call
                return StringExtensions.ParseJObject(jp.Value.ToString(), $"{parentFormat}{jp.Name}");
            }
            else
            {
                // normal member
                return $"{parentFormat}{jp.Name}={HttpUtility.UrlEncode(jp.Value.ToString())}";
            }
        }
    }

Friday, December 15, 2017

Vue 2.0 modal in Bootstrap 4, a confirmation modal example for everyone

I was a bit tired of looking for a suitable example of using a Bootstrap 4.0 modal within Vue.js.

Here is a Vue component to do just that.  I've included an example of how to use.  After the initial comments of the Example, everything else is your JavaScript component file.

I welcome comments if folks have improvements...but let's keep it simple for everyone else.

 // jQuery required as Bootstrap uses it, but if you use another non-jQuery  
 // modal framework, you can modify the show() function to remove jQuery modal 'show'  
 //  
 // Example:  
 //  
 // <div id="app">  
 //  <button type="button" class="btn btn-secondary" v-on:click="$refs.modal.show()">Modal</button>  
 //  <confirm-component ref="modal" v-bind:options="confirmOptions()" v-on:closeCancel="cancel" v-on:closeNo="no" v-on:closeYes="yes"></confirm-component>  
 // </div>  
 //  
 // <script>  
 // var vueApp = new Vue({  
 //  el: '#app',  
 //  ...  
 //  
 // confirmOptions() {  
 //  return {  
 //    title: '<i>Do you really want to do this?</i>',  
 //    message: 'Going to do something really <strong>major</strong>...continue?',  
 //  
 //    textCancel: 'CANCEL', // defaults to 'Cancel'  
 //    textNo: 'NO',     // defaults to 'No'  
 //    textYes: 'YES',    // defaults to 'Yes'  
 //  
 //    showNo: true,     // defaults to true  
 //    showNo: false,     // defaults to false  
 //    showYes: true     // defaults to true  
 //  };  
 // }  
 // cancel() {  
 //  alert('cancel');  
 // },  
 // no() {  
 //  alert('no');  
 // },  
 // yes() {  
 //  alert('yes');  
 // }  
 // });  
 // </script>  
   
   
 "use strict";  
 Vue.component('confirm-component', {  
    props: ['options'],  
    methods: {  
       show() {  
          $('#confirmModalComponent').modal('show');  
       }  
    },  
    computed: {  
       modalTitle() {  
          return this.options.title ? this.options.title : '';  
       },  
       modalMessage() {  
          return this.options.message ? this.options.message : '';  
       },  
       modalTextCancel() {  
          return this.options.textCancel ? this.options.textCancel : 'Cancel';  
       },  
       modalTextNo() {  
          return this.options.textNo ? this.options.textNo : 'No';  
       },  
       modalTextYes() {  
          return this.options.textYes ? this.options.textYes : 'Yes';  
       },  
       showCancel() {  
          return this.options.showCancel ? this.options.showCancel : true;  
       },  
       showNo() {  
          return this.options.showNo ? this.options.showNo : false;  
       },  
       showYes() {  
          return this.options.showYes ? this.options.showYes : true;  
       },  
       closeCancel() {  
          this.$emit('closeCancel');  
       },  
       closeNo() {  
          this.$emit('closeNo');  
       },  
       closeYes() {  
          this.$emit('closeYes');  
       }  
    },  
    template: `  
 <div class="modal fade" id="confirmModalComponent" tabindex="-1" role="dialog" aria-labelledby="confirmModalComponentLabel" aria-hidden="true">  
  <div class="modal-dialog" role="document">  
   <div class="modal-content">  
    <div class="modal-header">  
     <h5 class="modal-title" id="confirmModalComponentLabel" v-html="modalTitle"></h5>  
     <button type="button" class="close" data-dismiss="modal" aria-label="Close">  
      <span aria-hidden="true">&times;</span>  
     </button>  
    </div>  
    <div class="modal-body" v-html="modalMessage">  
    </div>  
    <div class="modal-footer justify-content-between">  
     <div>  
       <button v-if="showCancel" type="button" class="btn btn-primary" :click="closeCancel" data-dismiss="modal">{{modalTextCancel}}</button>  
     </div>  
     <div>  
       <button v-if="showNo" type="button" class="btn btn-primary" :click="closeNo" data-dismiss="modal">{{modalTextNo}}</button>  
       <button v-if="showYes" type="button" class="btn btn-success" :click="closeYes" data-dismiss="modal">{{modalTextYes}}</button>  
     </div>  
    </div>  
   </div>  
  </div>  
 </div>  
 `  
 });  

Saturday, November 25, 2017

Sunday, September 17, 2017

URL rewrite for https and www in ASPNET Core (Solved)

If you want to url rewrite to both https and www using ASP.NET Core 2.0, here is some pretty straight-forward C# you can add to your Startup.cs.

Woo-hoo!

// ...

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        // ...
    }
    else
    {
        // url rewrite; do this before UseStaticFiles
        var options = new RewriteOptions().Add(
            new RedirectRules(rewriteHttps: true, rewriteWww: true));
        app.UseRewriter(options);
    }

    // ...
}

// ...

public class RedirectRules : Microsoft.AspNetCore.Rewrite.IRule
{
    private readonly bool _rewriteHttps;
    private readonly bool _rewriteWww;

    public RedirectRules(bool rewriteHttps, bool rewriteWww)
    {
        _rewriteHttps = rewriteHttps;
        _rewriteWww = rewriteWww;
    }

    public void ApplyRule(RewriteContext context)
    {
        //
        // redirect two ways
        //    - http to https (if enabled)
        //    - non-www host to www host (if enabled)
        //

        const string hostRoot = "mydomain.com";
        var request = context.HttpContext.Request;
        var currentHost = request.Host;
        HostString newHost;

        // do we need to rewrite from http to https
        var isNewProtocol = _rewriteHttps && request.Scheme.ToLower() == "http";

        // do we need to rewrite from non-www host to www host
        if (_rewriteWww && currentHost.Host == hostRoot)
            newHost = new HostString($"www.{hostRoot}", currentHost.Port ?? 80);

        // if either rewrite done, create a new url
        if (isNewProtocol || newHost.HasValue)
        {
            var newUrl = new StringBuilder()
                .Append(isNewProtocol ? "https" : request.Scheme)
                .Append("://")
                .Append(newHost.HasValue ? newHost : currentHost)
                .Append(request.PathBase)
                .Append(request.Path)
                .Append(request.QueryString);
            context.HttpContext.Response.Redirect(newUrl.ToString(), permanent: true);
            context.Result = RuleResult.EndResponse;
        }
    }
}

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...