Skip to content

Instantly share code, notes, and snippets.

View noseratio's full-sized avatar

Andrew Nosenko noseratio

View GitHub Profile
// http://stackoverflow.com/q/31522642/1768303
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace UnobservedTaskExceptionDemo
{
class Program
{
static void Main(string[] args)
{
@noseratio
noseratio / make-msbuild-shim.ps1
Last active May 2, 2023 11:31
A workaround for "node-gyp is unable to find msbuild if VS2019 is installed": https://github.com/nodejs/node-gyp/issues/1663
<#
This is a workaround for "node-gyp is unable to find msbuild if VS2019 is installed"
https://github.com/nodejs/node-gyp/issues/1663
It create a shim EXE as "MSBuild\15.0\Bin\MSBuild.exe" to target "MSBuild\Current\Bin\MSBuild.exe"
By noseratio - MIT license - use at your own risk!
It requires admin mode, I use wsudo/wsudox (https://chocolatey.org/packages/wsudo) for that:
wsudo powershell -f make-msbuild-shim.ps1
#>
#Requires -RunAsAdministrator
@noseratio
noseratio / Diags.cs
Created June 22, 2020 11:10
Double-click the output in Visual Studio Output Window to go to that source file and line
public static class Diags
{
public static void Log(
string message,
[System.Runtime.CompilerServices.CallerMemberName] string callerName = "",
[System.Runtime.CompilerServices.CallerLineNumber] int lineNumber = 0,
[System.Runtime.CompilerServices.CallerFilePath] string filePath = "")
{
// trim trailing new line characters
var trimmedMessage = message.TrimEnd(Environment.NewLine.ToCharArray());
@noseratio
noseratio / TaskFromEvent.cs
Last active May 2, 2023 11:30
Wrap an event as Task
/// <summary>
/// Wrap an event as Task
/// </summary>
/// <see href="https://stackoverflow.com/a/22798789/1768303"/>
public static async Task<TEventArgs> FromEvent<TEventHandler, TEventArgs>(
Func<Action<TEventArgs>, Action, Action<Exception>, TEventHandler> getHandler,
Action<TEventHandler> subscribe,
Action<TEventHandler> unsubscribe,
Action<Action<TEventArgs>, Action, Action<Exception>> initiate,
CancellationToken token = default) where TEventHandler : Delegate
@noseratio
noseratio / EventHandlerScope.cs
Last active May 2, 2023 11:30
Handle an event with a scope
/// <summary>
/// Handle an event with a scope, e.g.:
/// </summary>
/// <example>
/// <code>
/// using (new EventHandlerScope<FormClosedEventHandler>(
/// (s, e) => cts.Cancel(),
/// handler => form.FormClosed += handler,
/// handler => form.FormClosed -= handler))
/// {
@noseratio
noseratio / oauth2-desktop-apps.md
Last active May 2, 2023 11:30
Some questions about OAuth 2.0 for native (desktop) apps

Some questions I took an opportunity to ask in this Twitter thread:

  • How bad would it be to include a very short-lived OTP in a custom protocol URL link inside a web page, which takes user from their default browser to a locally installed native desktop app (say, Electron or WPF based)? So they don't have to authenticate again within the native app. More context here.

  • Most native desktop apps (e.g., MS Teams) don't seem to follow RFC8252 that requires to use external user-agents (i.e. default browsers) for authorization flow. Instead, they "cheat" and use their own internal WebView to host the external OAuth providers web UI. What's the reason behind this choice? Is this only because it's allegedly considered user-unfriendly to lauch the default browser? Should the industry come up with some

@noseratio
noseratio / paste-unfromatted-by-default.md
Last active May 2, 2023 11:29
Would you prefer Ctrl+V to paste unformatted text by default for any app, controlled by a setting?

Ctrl+Shift+V is nice for when and where it works.

Would you rather prefer Ctrl+V to paste unformatted text by default into any Windows app?

I personally think I want this behavior by default, and I could add this feature to DevComrade (free and open-source), if there's enough interest.

If you feel it's a good idea, please upvote this DevComrade issue, discuss it here or respond to my original tweet.

@noseratio
noseratio / _invoke-build.ps1
Last active May 2, 2023 11:29
find Visual Studio and run its VsDevCmd.bat, then $buildCommand
<#
.Synopsis
Find Visual Studio and run its VsDevCmd.bat, then run a build command.
.Example
powershell -f _invoke-build.ps1 -buildCommand "msbuild ."
.Link
https://gist.github.com/noseratio/843bb4d9c410c42081fac9d8b7a33b5e
#>
@noseratio
noseratio / my-chocolatey-packages.txt
Last active May 2, 2023 11:28
My installed chocolatey packages
Chocolatey v0.10.15
7zip 19.0
7zip.install 19.0
adb 30.0.4
azure-cli 2.13.0
bitvise-ssh-client 8.44
calibre 5.3.0
cascadiacode 2009.21
cascadiacodepl 2009.21
cascadiafonts 2009.21