Skip to content

Instantly share code, notes, and snippets.

View noseratio's full-sized avatar

Andrew Nosenko noseratio

View GitHub Profile
@noseratio
noseratio / DistinctSubject.cs
Created September 19, 2021 09:05
Rx .NET DistinctSubject
public class DistinctSubject<T> : SubjectBase<T>
{
// based on https://github.com/dotnet/reactive/blob/main/Rx.NET/Source/src/System.Reactive/Subjects/BehaviorSubject.cs
// also: https://stackoverflow.com/q/69239022/1768303
// TODO: unit tests
private object _lock = new();
private T _value;
private readonly EqualityComparer<T> _comparer;
@noseratio
noseratio / AddFactory.cs
Last active May 2, 2023 11:24
A factory for ActivatorUtilities.CreateInstance
// https://stackoverflow.com/q/69207420/1768303
#nullable enable
using System;
using System.Diagnostics;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
namespace App
{
static class Program
@noseratio
noseratio / rx-net-debouncing-throttling.cs
Last active September 6, 2021 13:16
Rx.NET debouncing and throttling
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
static async IAsyncEnumerable<int> Produce()
{
for (int i = 0; i < 10; i++)
@noseratio
noseratio / WebView-AspNetCore.csproj
Last active May 2, 2023 11:24
Combine AspNetCore, WebView2 and WPF in the same NET 5 Desktop project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<OutputType>Exe</OutputType>
<DisableWinExeOutputInference>true</DisableWinExeOutputInference>
<UseWPF>true</UseWPF>
<UsingMicrosoftNETSdkWeb>true</UsingMicrosoftNETSdkWeb>
<StartupObject>WebView2AppKeys.Program</StartupObject>
@noseratio
noseratio / purge-vs-bins.cmd
Last active August 25, 2021 07:11
Delete VS build artefacts
@echo off
set folders=bin obj .vs
echo This will delete all [%folders%] folders recursively and cannot be undone.
choice /t 10 /d n /c yn /m "Press Y to continue, N to stop"
if %errorLevel% neq 1 goto :EOF
for /d /r . %%D in (%folders%) do if exist "%%~fD\" (echo %%D && rd "%%~fD" /s /q)
@noseratio
noseratio / purge-node-modules.cmd
Last active June 15, 2023 17:29
Delete node_modules recursively on Windows
@echo off
set folders=node_modules
echo This will delete all [%folders%] folders recursively and cannot be undone.
choice /t 10 /d n /c yn /m "Press Y to continue, N to stop"
if %errorLevel% neq 1 goto :EOF
for /d /r . %%D in (%folders%) do if exist "%%~fD\" (echo %%D && rd "%%~fD" /s /q)
import kotlinx.coroutines.*
suspend fun suspendableDelay(ms: Long): Long {
delay(ms);
return ms;
}
fun regularDelay(ms: Long): Deferred<Long> {
val d = CompletableDeferred<Long>()
GlobalScope.async { delay(ms); d.complete(ms) }
// https://try.dot.net/?bufferId=trydotnet.cs&fromGist=717d378bc9f14db1ed30d0e2e67b0534
// async/await doesn't work on try.dot.net, an open issue since Oct 2019:
// https://github.com/dotnet/try/issues/527
using System;
using System.Threading.Tasks;
public class Program
{
public static async Task Main()
{
Console.WriteLine("Hello...");
@noseratio
noseratio / use_existing_session.patch
Created August 3, 2021 11:01 — forked from nightuser/use_existing_session.patch
Use existing Xorg session for chrome-remote-desktop
Add an option to use the existing Xorg session with
chrome-remote-desktop.
The original idea of the patch: https://superuser.com/a/850359
--- a/chrome-remote-desktop 2021-04-05 11:53:16.537908500 +0000
+++ b/chrome-remote-desktop 2021-04-05 12:04:52.768536483 +0000
@@ -107,6 +107,8 @@
X_LOCK_FILE_TEMPLATE = "/tmp/.X%d-lock"
FIRST_X_DISPLAY_NUMBER = 20
@noseratio
noseratio / addDisposableEventListener.js
Last active May 2, 2023 11:25
disposable event listener
if (!EventTarget.prototype.addDisposableEventListener) {
EventTarget.prototype.addDisposableEventListener = function(type, listener, options) {
this.addEventListener(type, listener, options);
return () => this.removeEventListener(type, listener);
}
}
const dispose = document.body.addDisposableEventListener(
'click', () => console.log('clicked!'));
try {