Skip to content

Instantly share code, notes, and snippets.


Rick Strahl RickStrahl

View GitHub Profile
RickStrahl / gist:204de6f9e6607b79010f5e7648b0d1a7
Last active Sep 12, 2016
Angular 2 HttpClient Wrapper Problems
View gist:204de6f9e6607b79010f5e7648b0d1a7
import {Injectable} from "@angular/core";
import {Http, RequestOptionsArgs, Response} from "@angular/http";
import {UserInfo} from "./userInfo";
import {CatchSignature} from "rxjs/operator/catch";
import {Observable} from "rxjs";
* Wrapper around the Http provider to allow customizing HTTP requests
RickStrahl / CheckForMarkdownMonster.cs
Created Dec 19, 2016
Sample that demonstrates the difference when running Visual Studio debugger in 32 bit instead of 64 bit as expected.
View CheckForMarkdownMonster.cs
string mmFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),"Markdown Monster");
string path = sk.GetValue("Path").ToString();
if (!path.Contains(mmFolder))
var pathList = path.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
path = string.Join(";", pathList.Distinct().ToArray());
sk.SetValue("Path", path);
View mobi2goSocketIoWrapper.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mobi2GoClient.Entities;
using Newtonsoft.Json.Linq;
using Quobject.EngineIoClientDotNet.Client;
using Quobject.SocketIoClientDotNet.Client;
using Socket = Quobject.SocketIoClientDotNet.Client.Socket;
RickStrahl /
Last active Oct 2, 2017
Adding Authorization to a Generic Controller defined in an imported assembly

In my component I publish a UI component that uses an API controller to handle updating of application resources generically. There is a base .NET library that provides core localization services and an ASP.NET Core specific library that provides features specifically for ASP.NET.

The issue is how to allow the API Controller - which lives inside of the generic component and is not touched by the application directly - to be secured easily.

I ended with the following code:

services.AddWestwindGlobalization(opt =>

Marking up the World with Markdown

Markdown has easily been one of the most influential technologies that have affected me in the last few years. Specifically it has changed how I work with documentation and a number of documents both for writing and also for text editing and content storage inside of applications.

Markdown is a plain text representation of HTML typically. Markdown works using a relatively small set of easy to type markup mnemonics to represent many common document centric HTML elements like bold, italic, underlined text, ordered and unordered lists, links and images, code snippets, tables and more. This small set of markup directives is easy to learn and quick to type in any editor without special tools or applications.

In the past I've been firmly planted in the world of rich text editors like Word, or using a WYSIWYG editor on the Web, or for Blog Editing using something like Live Writer which used a WYSIWYG editor for post editing. When I first discovered Markdown a number of years a

View TestDynamic.prg
DO wwDynamic
DO wwJsonSerializer
loCust = CREATEOBJECT("TestClass")
loItem = CREATEOBJECT("wwDynamic",loCust)
*loItem = CREATEOBJECT("wwDynamic")
RickStrahl /
Created Jan 29, 2019
Markdown Monster Math Expressions with MathJax

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
RickStrahl / GitHubRespositoryGraphQl.cs
Last active Feb 23, 2019
Recursively parse a Github Repository with GraphQL
View GitHubRespositoryGraphQl.cs
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

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) {
RickStrahl /
Last active Feb 25, 2020
Masking IWebHostEnvironment in .NET Core 2.x for operation like 3.x

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.

using Microsoft.Extensions.FileProviders;

namespace Microsoft.AspNetCore.Hosting