Skip to content

Instantly share code, notes, and snippets.

View RickStrahl's full-sized avatar

Rick Strahl RickStrahl

View GitHub Profile
@RickStrahl
RickStrahl / UsingGistsForGeneralPurposeWebPagesWithMarkdown.md
Last active September 6, 2022 19:29
Using Gists for General Purpose Web Pages with Markdown
title abstract keywords categories weblogName postId
Using Gists for General Purpose Web Pages with Markdown
Most of you probably know and use Github Gists for sharing Code snippets. But did you know that Gists also support Markdown? Using Markdown makes it easy to create much richer code shareable code and even allows for an easy way to create self-contained Web content.
Gist,Markdown,Share,Social Media
Markdown
West Wind Web Log
502103

Using Gists for General Purpose Content with Markdown

This works with an abstract class:

Base class:

/// <summary>
/// Handles the Administration Form API backend tasks
/// </summary>
[Route("api/LocalizationAdministration")]
[UnhandledApiExceptionFilter]    
@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 =>
{                
@RickStrahl
RickStrahl / Inno File Associations.txt
Created June 29, 2017 08:09
File Association Registry Settings
[Registry]
; File Association for .md and .markdown
Root: HKCR; Subkey: ".md"; ValueData: "{#MyAppName}"; Flags: uninsdeletevalue; ValueType: string; ValueName: ""
Root: HKCR; Subkey: ".markdown"; ValueData: "{#MyAppName}"; Flags: uninsdeletevalue; ValueType: string; ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}"; ValueData: "Program {#MyAppName}"; Flags: uninsdeletekey; ValueType: string; ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}\DefaultIcon"; ValueData: "{app}\{#MyAppExeName},0"; ValueType: string; ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}\shell\open\command"; ValueData: """{app}\{#MyAppExeName}"" ""%1"""; ValueType: string; ValueName: ""
@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)
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;
[TestMethod]
public void BitmapWpfPngSaveTest()
{
Assert.IsTrue(System.Windows.Clipboard.ContainsImage(), "No image on clipboard");
string of = "c:\\temp\\test_Bitmap.png";
var bmpSource = System.Windows.Clipboard.GetImage();
using (var fileStream = new FileStream(of, FileMode.Create))
public void ImageSharpClipboardTest()
{
string of = "c:\\temp\\test_imagesharp.png";
Assert.IsTrue(Clipboard.ContainsImage(), "No image on clipboard");
var img = Clipboard.GetImage();
ImageConverter converter = new ImageConverter();
byte[] bytes = (byte[])converter.ConvertTo(img, typeof(byte[]));
@RickStrahl
RickStrahl / file.cs
Created January 22, 2017 21:52
Gist Addin OnExecute() code that fires off the Addin's UI.
public override void OnExecute(object sender)
{
var editor = GetMarkdownEditor();
if (editor == null)
return;
var gist = new GistItem()
{
code = editor.AceEditor.getselection(false),
language = "cs"
@RickStrahl
RickStrahl / CSharpStringInterpolation.cs
Created December 27, 2016 11:22
LinqPad Sample Code for CSharp String Interpolation
void Main()
{
var msg = $".NET Version: {Environment.Version.ToString()}";
msg.Dump();
StringFormat();
BasicInterpolation();
MultiLine();