{{ message }}

Instantly share code, notes, and snippets.

Rick Strahl RickStrahl

Last active Oct 10, 2021
Drop in JavaScript status() function that can be used from code to display debug status message on the bottom of the viewport for scenarios where console.log() is not available.
View StatusDisplay.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 var statusTimeout = null; var statusDefaultTimeout = 10000; /* * Generic Status Message for the bottom of the screen. Can be used to render debug output * into the editor. Double click status bar to clear for appended output. * status('Started'); * status('updated',true, 5000); */ function status(msg, append, timeout) {
Last active Feb 25, 2020
Masking IWebHostEnvironment in .NET Core 2.x for operation like 3.x
View LegacyHostEnvironment.md

IWebHostingEnvironment is not available in .NET Core 2.x, but in 3.x it's the recommended way to access the host environment with threat of IHostingEnvironment being removed in the future. This can be a problem in libraries that need to run both on 2.x and 3.x.

The following tries to mask the differences in a multi-targeted .NET Core project by creating a custom IWebHostEnvironment implementations that picks up values from IHostingEnvironment in 2.x.

#if NETCORE2
using Microsoft.Extensions.FileProviders;

namespace Microsoft.AspNetCore.Hosting
{
Last active Oct 10, 2021
UrlEncoding on local Urls producing double encoded Uri.AbsoluteUri values
View AbsoluteUriUrlEncoding.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 void Main() { var part1 = new Uri("C:\\temp\\"); // double encodes when combining parts var part2 = "assets/Image%20File.jpg"; var uri = new Uri(part1, part2); uri.Dump(); uri.ToString().Dump(); // still encoded and shouldn't be
Last active Apr 11, 2019
View DateFormattingWithLibrary.md

You can do simple date formatting with a library by using the Intl.DateTimeFormat JavaScript class.

MDN for DateTimeFormat

alert( formatDate(new Date()));
// Apr 11, 2019, 1:10:40 PM

function formatDate(date, locale) {
Last active Feb 23, 2019
Recursively parse a Github Repository with GraphQL
View GitHubRespositoryGraphQl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Octokit.GraphQL; using Octokit.GraphQL.Model; namespace GithubGraphQl {
Last active Sep 29, 2021
A few different approaches to dynamically execute C# code dynamically at runtime from a string of code.
View CompilingCSharpCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Scripting; using Microsoft.CodeAnalysis.Scripting; using Mono.CSharp; using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Diagnostics; using System.Dynamic; using System.Linq;
Created Jan 29, 2019
Markdown Monster Math Expressions with MathJax
View MarkdownMonster-Mathjax.md
useMath
true

Math Expressions using MathJax

Markdown Monster has built in support for rendering Math expressions using Latex, MathML and AsciiMath syntax. In order to use Math expressions on your page you have to explicit ask for it via the useMath YAML header:

---
useMath: true
Last active Feb 17, 2021
Markdown Monster Mermaid Sample
View MarkdownMonster-Mermaid.md

Mermaid

Mermaid is a JavaScript based parsing engine that allows you to embed blocks of graph markup into a page. Markdown Monster supports two different approaches using either code block or HTML tag syntax to embed the mermaid blocks.

@icon-warning Internal Preview Limitations

Note the MM internal preview can't properly display or refresh all chart types, but you can preview in your system browser via Shift-F12 to see proper representation.

Sequence Diagram

You can use a mermaid code block:

Last active Oct 10, 2021
View XmlElementsAndAttributes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 void Main() { var doc = new XmlDocument(); doc.LoadXml("This is & a \"test\" and a 'tested' test"); doc.OuterXml.Dump(); var node = doc.CreateElement("d2"); node.InnerText = "this & that and \"test\" and 'tested'"; doc.DocumentElement.AppendChild(node); var attr = doc.CreateAttribute("note","this & that and \"test\" and 'tested'");
Last active Nov 23, 2018
View TestDynamic.prg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 DO wwDynamic DO wwJsonSerializer CLEAR loCust = CREATEOBJECT("TestClass") loItem = CREATEOBJECT("wwDynamic",loCust) *loItem = CREATEOBJECT("wwDynamic")