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

Testing Markdown Parser

June 17, 2024|

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

June 4, 2024|

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

April 8, 2024|

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

March 18, 2024|

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

March 15, 2024|

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 [...]

Ignore First Render in React’s useEffect()

October 16, 2023|

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

October 10, 2023|

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

February 17, 2021|

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

October 29, 2020|

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

October 28, 2020|

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

February 11, 2019|

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

August 6, 2018|

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 – Get Ajax Post Error Details

August 6, 2018|

$.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

November 14, 2020|

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

October 28, 2020|

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 [...]

Entity Framework Core Model in .NET Framework 4x Project

October 23, 2020|

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 [...]