Skip to content

Instantly share code, notes, and snippets.

View noseratio's full-sized avatar

Andrew Nosenko noseratio

View GitHub Profile
@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 / AsyncEvents.ToAsyncEnumerable.Reactive.cs
Created July 17, 2020 03:27
Combine multiple Rx.NET observables and read them as IAsyncEnumerable
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
#nullable enable
@noseratio
noseratio / CancellablePromise.js
Last active September 7, 2020 11:15
Cancellable JavaScript Promise
// by @noseratio
// https://gist.github.com/noseratio/141a2df292b108ec4c147db4530379d2
// https://runkit.com/noseratio/cancellablepromise
const prex = require('prex');
/**
* A cancellable promise.
* @extends Promise
*/
@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 / async-generator.js
Last active March 28, 2021 22:09
Async generators and "for await" in JavaScript
// by @noseratio
// https://twitter.com/noseratio/status/1297517388552757249?s=20
// gist: https://gist.github.com/noseratio/721fea7443b74a929ea93c8f6a18cec4/edit
// RunKit: https://runkit.com/noseratio/async-generators-and-for-await-in-javascript
async function delay(ms) {
await new Promise(r => setTimeout(r, ms));
return ms;
}
@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 / TaskSchedulerAwaiter.cs
Created September 16, 2020 11:29
Continue on the specified task scheduler, which becomes the current one
// by @noseratio
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace Noseratio.Experimental
@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 / rollup-acorn-conf.js
Last active October 24, 2020 03:16
Adding Acorn plugins to Snowpack workflow
"use strict";
// https://stackoverflow.com/a/64501702/1768303
module.exports = function plugin(snowpackConfig, pluginOptions) {
const name = "rollup-acorn-conf";
snowpackConfig.installOptions = snowpackConfig.installOptions ?? {};
snowpackConfig.installOptions.rollup = snowpackConfig.installOptions.rollup ?? {};
snowpackConfig.installOptions.rollup.plugins = snowpackConfig.installOptions.rollup.plugins ?? [];
@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