This site is my repository for code samples. It is a means for me to document solutions to common problems so that I can reference them quickly when needed, both at work and at home. Samples will be added to this site over the next year or two as I slowly migrate them from (1,074) text files that have served as my repository for over a decade. (I don’t want to do a mass migration as I want each sample to be properly reviewed, formatted, categorized, and tagged. I try to migrate samples as I reference them, time permitting.)
Some samples are complex, some are simple. Some are correct, and some are incorrect. While my intention is that I will be the only user of this site (I’m not an expert, and I don’t expect my samples to solve your code problems!), I don’t see a reason to prevent this content from being available to the general public. Just be warned that this content is not being shared as “the right way” to do things.
That being said, if you do happen to see glaring errors, or have suggestions on how something could be done better, feel free to contact me.
jQuery
Check If Element Has ID Using jQuery
To check if an element has an ID: if ($(this).is('[id]') { // Has ID console.log('Has ID: ' + $(this).attr('id')); } else { // Has no ID console.log('Has no ID.'); }
jQuery – Selector Starts-Ends With
Selector Starts With: $('input[name^=somePrefix]').doSomething(); Selector ENDS with: $('input[name$=someSuffix]').doSomething(); In ASP.Net: This is particularly useful in ASP.Net when you may not want to specify clientidmode static, but still want to use jQuery to find the ID. [...]
jQuery – Bind to Document Instead of Elements for Dynamic Elements
When a DOM object is added after the DOM has loaded, the usual process of binding an event to a specific jQuery object may not be sufficient. E.g.: Normal binding to a button $(function() { [...]
jQuery – Get Ajax Post Error Details
$.post('status.ajax.php', {deviceId: id}) .done( function(msg) { ... } ) .fail( function(xhr, textStatus, errorThrown) { alert(xhr.responseText); }); http://stackoverflow.com/a/12116790/4669143
ASP.Net
React Component with Children
Creating a React component that contains children can be as easy as including a children property and including {props.children} in the Return function. But knowing the proper type to use for the children property (when [...]
Working As a Team with Migrations in Entity Framework Core
The official Microsoft documentation for using Migrations in Team Environments covers the basics. However, they neglect to mention one very important thing: Removing Migrations in a Team Environment Can Be Deadly! Well, not deadly, but [...]
Getting Latest Published Version of Document in SharePoint API CSOM
I occasionally have to use the SharePoint .Net Client-Side Object Model (CSOM) API to reach into SharePoint and poke around a little bit. It's all pretty straightforward, but something that I have not found to [...]
Returning Status Codes in an ASP.Net MVC Core Controller
There are a few ways to return different status codes in an ASP.Net MVC Core controller. Simplified Helper Methods Some helper methods for the most common codes (there may be more than the list below): [...]
CSS
Fancy Checkboxes and Toggle Switches
This allows you to replace default checkboxes with a nicer-looking custom font alternative. This example uses Font Awesome 4 icons, but the CSS could easily be modified to use any font. For the code below [...]
Preserve White Space in Static Text Without Using PRE Tag
When displaying multi-line text (e.g. input from a TextArea) in a static element (e.g. DIV), extra white space and line breaks are ignored, resulting in one long line of text. An older approach used to [...]