Skip to content

Instantly share code, notes, and snippets.

View RickStrahl's full-sized avatar

Rick Strahl RickStrahl

View GitHub Profile
@RickStrahl
RickStrahl / CompilingCSharpCode.cs
Last active April 3, 2024 14:11
A few different approaches to dynamically execute C# code dynamically at runtime from a string of code.
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;
@RickStrahl
RickStrahl / ColorConsole.cs
Last active March 30, 2024 16:00
Color Console - a simple class to add color to .NET Console commands more easily.
using System;
using System.Text;
using System.Text.RegularExpressions;
namespace MainColorConsole
{
class Program
{
static void Main(string[] args)
{
@RickStrahl
RickStrahl / MarkdownMonster-Mermaid.md
Last active March 18, 2024 14:54
Markdown Monster Mermaid Sample

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:

@RickStrahl
RickStrahl / TcpIp-WebSer-AppSpecific.cs
Created November 28, 2023 08:35
A minimal, app-specific TCP/IP Web Server using .NET Code. Very simplistic manual request parsing and 'routing' for a few simple operations against the server.
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MarkdownMonster.Controls;
@RickStrahl
RickStrahl / Slug.cs
Created January 4, 2018 07:57
Generate Slug
/// <summary>
/// Creates a unqique slug
/// </summary>
/// <param name="titleText"></param>
/// <returns></returns>
public string CreateSlug(string titleText = null)
{
if (titleText == null)
titleText = Title;
if (string.IsNullOrEmpty(titleText))
@RickStrahl
RickStrahl / StatusDisplay.js
Last active November 27, 2023 13:18
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.
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) {
@RickStrahl
RickStrahl / SimpleWebSocketServer-Usage.cs
Last active November 27, 2023 13:18
Simple Notification Only C# WebSocket Server
if (WebSocketServer == null)
{
WebSocketServer = new MarkdownMonster.WebSockets.WebSocketServer();
WebSocketServer.StartServer();
WebSocketServer.OnBinaryMessage = (bytes) =>
{
App.CommandArgs = new[] {"untitled.base64," + Convert.ToBase64String(bytes)};
mmApp.Model.Window.Dispatcher.InvokeAsync(() => mmApp.Model.Window.OpenFilesFromCommandLine());
};
}
void Main()
{
var doc = new XmlDocument();
doc.LoadXml("<d><t>This is &amp; a \"test\" and a 'tested' test</t></d>");
doc.OuterXml.Dump();
var node = doc.CreateElement("d2");
node.InnerText = "this & that <doc> and \"test\" and 'tested'";
doc.DocumentElement.AppendChild(node);
var attr = doc.CreateAttribute("note","this & that <doc> and \"test\" and 'tested'");
@RickStrahl
RickStrahl / DebounceDispatcher.cs
Last active November 27, 2023 13:17
Debouncing events by a timeout using a Dispatcher.
public class DebounceDispatcher
{
private DispatcherTimer timer;
public void Debounce(int timeout, Action<object> action,
object param = null,
DispatcherPriority priority = DispatcherPriority.ApplicationIdle,
Dispatcher disp = null)
{
if (disp == null)

Windows Setup Notes

based on original document from Alan Stevens

Installation

IMPORTANT:

  • Install using Local Account first, attach Microsoft account later