Skip to content

Instantly share code, notes, and snippets.

View RickStrahl's full-sized avatar

Rick Strahl RickStrahl

View GitHub Profile
@RickStrahl
RickStrahl / Bash-ShellExecute.cs
Last active May 19, 2020 21:48
Trying to run `bash -c ""` command with Process.Start/ShellExecute
// works in LinqPad
void Main()
{
ExecuteCommandLine("wt"); // works - this is resolved
ExecuteCommandLine("bash"); // The system cannot find the file specified
// actual command line I'm trying to fire
ExecuteCommandLine("bash -c \"cd /mnt/c/projects/Test/jekyll/help; bundle exec jekyll serve\"");
}
[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))
@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();

This works with an abstract class:

Base class:

/// <summary>
/// Handles the Administration Form API backend tasks
/// </summary>
[Route("api/LocalizationAdministration")]
[UnhandledApiExceptionFilter]    
@RickStrahl
RickStrahl / RunVsCodeFromDotnet.cs
Last active October 11, 2021 02:15
Demonstrates different ways to launch VS Code from C# code on Windows
void Main()
{
string file = @"C:\temp\test.md";
OpenFileInTextEditorRegistry(file);
//OpenEditorWithShellExecute(file);
//OpenWithProcessStartFailed(file);
}
@RickStrahl
RickStrahl / Defender.md
Created October 5, 2018 19:52
Turn Defender Real-Time Protection On and Off

Defender's real time protection can significantly slow down disk and IO bound operations on Windows, so if you're doing disk intensive work or stress tests I find turning off Defenders Real Time Protection can improve performance drastically.

The following Powershell script provides a quick way to turn Powershell Real Time protection on and off quickly. Dump this file into a folder on your path to quickly turn.

##################################################
# Turn Defender Real Time Monitoring off

# turns defender real time monitoring -on or -off 
# Has to run under an Admin prompt
@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 / BitmapSourceToBitmap.cs
Last active October 11, 2021 02:21
BitmapSource To Bitmap Conversion
/// <summary>
/// Converts a bitmap source to a bitmap
/// Make sure to dispose the bitmap
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static Bitmap BitmapSourceToBitmap(BitmapSource source)
{
if (source == null)
return null;
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 / 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: ""