Simple jQuery Plugin Working Example

I recently started developing a jQuery plugin for a project.  I found jQuery plugin development to be very interesting and can see many areas where I can use plugins going forward.

One of the best overviews of plugins I have found was over at WebDevEasy.  The author discusses plugins that work on an element and plugins that do not.  

After writing a couple of jQuery plugins that were meant to handle processing vs. elements, I decided to post this template for myself for future use. 

First the Plugin Code:  The following code has one Public and one Private function. This plugin is not meant to work on an element but meant to handle the processing required by calling a public method.  

The function starts with a semi-colon before (function ($) as a way to protect this plugin if another developer did not end their plugin with a semi colon. 
;(function ($) {
        
    //----------------------------------------
    // Create Plugin
    //----------------------------------------
    $.myPlugin = function (param1, param2) {

        //-------------------
        // Public Functions
        //-------------------       
        return {
            //---------------------
            // Public functions
            //----------------------
            myPublicFunction: function (param1) {
                myPrivateFunction(param1);
            },
        };
    };
    //End Plugin ----------------------

    //===========================================
    //===========================================
    // Private Functions 
    //===========================================
    //===========================================
    function myPrivateFunction(param1)
    {
        console.log('myPrivateFunction(): ' + param1);
    }

})(jQuery);

Plugin Use:  The following button click event calls a function which in turns calls a public method of the plugin.
<button onclick="pluginTest();">Test Plugin</button>
Get an instance of the plugin and call myPublicFunction()
function pluginTest() {
    var myTestPlugin = $.myPlugin('This is Param 1', 'This is Param 2');
    myTestPlugin.myPublicFunction('This is Param 1');
}

Results from the console:
myPrivateFunction(): This is Param 1

Enable Num Lock During Chrome Remote Desktop

Using Chrome Remote Desktop the Num Lock key goes out of sync.  This means if you turn the num lock OFF on your computer and you connect via Chrome Remote Desktop the num lock will be ON for your session.  If you turn num lock ON on your computer, it will be OFF on your remote session.

There is a free Windows App called Num Locker that will keep your num lock enabled at all times. This is a great fix for this issue with Chrome Remote Desktop. Download it from the link below.

NumLocker_v1.0.zip (451.4KB)

C# LINQ In Clause

In Clause in LINQ can seem a bit tricky when you first write one. These two Northwind Traders SQL examples of a LINQ In Clause includes using a list as the in clause, and using a query as the in clause.

//--------------------------------------------------------------------------------    
//1. In Clausing using a LIST
//--------------------------------------------------------------------------------
List<decimal> OrderList = new List<decimal>();    
OrderList.Add(10248);
OrderList.Add(10250);
var OrderListArr = OrderList.ToArray();

var CustOrders = from o in Orders
                 where OrderListArr.Contains(o.OrderID)
                 select o;
    
CustOrders.Dump();

//--------------------------------------------------------------------------------
//2. In Clause using a LINQ statement. Get Customer Orders from Brazil customers
//--------------------------------------------------------------------------------
var BrazilOrders = from o in Orders
                   where (from c in Customers
                         where c.Country.Contains("Brazil")
                         select c.CustomerID).Contains(o.CustomerID)
                   select o;
BrazilOrders.Dump();           

Screen Shot from LINQPad for the two queries above.