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);
}
@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();
@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"
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[]));
[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))
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 / 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)
@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 / 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 =>
{