This 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. Samples will be added to this site over time as I slowly migrate them from the thousands of text files that have served as my repository until now.
Some code samples are complex, some are simple, some are correct, and some are incorrect. While I expect to be the only user of this site (I don't expect my samples to solve your code problems!), I don't see why this content shouldn't be available to others. Just be warned that these articles aren't being presented as "the right way" to do things.
That being said, if you do happen to see glaring errors, or have suggestions that could improve some of the content, feel free to contact me.
Recent Posts: All Categories
Center Flexbox Column Between Two Variable-Width Columns (Common Toolbar Scenario)
The Issue I often run into the scenario where I'm building a toolbar with items on the left, in the middle, and on the right. The items on the left and right can often be [...]
Testing Markdown Parser
Testing code blocks in HTML tags Testing Markdown inside a details/summary block Hidden Code Sample ```js console.log('5'); ``` console.log('5'); Testing markdown wrapped in a DIV Test H2 Code sample: console.log('5'); Testing custom Input/Output: ```js [...]
Testing Highlight.js
Testing command line code hint (cmd): rem This is a test netsh delete ipport=0.0.0.0:44369 Code fence with no lang hint will have language auto-detected by highlight.js: ``` console.log("this is a test"); ``` console.log("this is a [...]
Post Guidelines
Background This site uses Markdown for simplified input. Specifically, it adheres to the CommonMark spec. Code is highlighted using highlight.js. Adding Code to a Post There are two ways to add code to a post [...]
Recent Posts: React
Memoize React Components to Prevent Unnecessary Renders
When the state of a React component changes, the component and all of its children will re-render. While this is fine for most cases, you may have a child component that does some heavy computation, [...]
Styled Component Properties in React
By default, properties passed to a styled component are passed on as attributes to the native HTML element created. A regular property must be a valid HTML element attribute, or there will be an error [...]
Updating Input and Triggering onChange Event Programmatically in React
While it's easy to update an input's value using a ref, that doesn't trigger the input's onChange event, which may be an issue if you're relying on onChange to fire when the input value changes. [...]
Ignore First Render in React’s useEffect()
Sometimes you want to use useEffect() to catch a change in a state, but only after the initial value has been set. For example, you have a state called selectedId, and you want to do [...]
Recent Posts: Entity Framework
Relationships in Entity Framework Core 7
One to Many Relationships This article does not yet include information about One-To-Many relationships in Entity Framework Core 7. However, One-To-Many relationships have not changed much since Entity Framework Core 3, so check out this [...]
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 [...]
Force Strings to use VARCHAR in Entity Framework Core
The nvarchar data type requires twice as much space to store as an equivalent-length varchar. For that reason, it is usually recommended to use varchar when you don't have a requirement to store Unicode characters. [...]
Seed Identity Data in ASP.Net Core
When using Identity in ASP.Net Core, it can be useful to seed some data for testing purposes. How to go about that is not entirely obvious, given that the tables involved (IdentityRole, IdentityUser, IdentityUserRole) aren't [...]
Recent Posts: 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
Recent Posts: ASP.Net
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): [...]
Seed Identity Data in ASP.Net Core
When using Identity in ASP.Net Core, it can be useful to seed some data for testing purposes. How to go about that is not entirely obvious, given that the tables involved (IdentityRole, IdentityUser, IdentityUserRole) aren't [...]
C# Razor Syntax Quick Reference (Link Only)
https://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/
Entity Framework Core Model in .NET Framework 4x Project
Because .NET Standard is implemented by later versions of the .NET Framework and .NET Core, these two very different project types can actually play nicely together. (I think of .NET Standard like an interface implemented [...]