Skip to content

Instantly share code, notes, and snippets.

View RickStrahl's full-sized avatar

Rick Strahl RickStrahl

View GitHub Profile
@RickStrahl
RickStrahl / gist:204de6f9e6607b79010f5e7648b0d1a7
Last active September 12, 2016 03:42
Angular 2 HttpClient Wrapper Problems
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
*/
@Injectable()
@RickStrahl
RickStrahl / CheckForMarkdownMonster.cs
Created December 19, 2016 10:54
Sample that demonstrates the difference when running Visual Studio debugger in 32 bit instead of 64 bit as expected.
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();
pathList.Add(mmFolder);
path = string.Join(";", pathList.Distinct().ToArray());
sk.SetValue("Path", path);
}
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
RickStrahl / GenericAuthorizationToGenericController.md
Last active October 2, 2017 00:22
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

DO wwDynamic
DO wwJsonSerializer
CLEAR
loCust = CREATEOBJECT("TestClass")
loItem = CREATEOBJECT("wwDynamic",loCust)
*loItem = CREATEOBJECT("wwDynamic")
@RickStrahl
RickStrahl / MarkdownMonster-Mathjax.md
Created January 29, 2019 04:12
Markdown Monster Math Expressions with MathJax
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
@RickStrahl
RickStrahl / GitHubRespositoryGraphQl.cs
Last active February 23, 2019 02:41
Recursively parse a Github Repository with GraphQL
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
RickStrahl / LegacyHostEnvironment.md
Last active February 25, 2020 07:27
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.

#if NETCORE2
using Microsoft.Extensions.FileProviders;

namespace Microsoft.AspNetCore.Hosting
{