Skip to content

Instantly share code, notes, and snippets.

View noseratio's full-sized avatar

Andrew Nosenko noseratio

View GitHub Profile
@noseratio
noseratio / adb-clear-packages.ps1
Last active April 17, 2024 00:43
Clear all Android packages and user data via ADB
# Clear all Android packages and user data via ADB, by @noseratio
# Run: powershell -f adb-clear-packages.ps1
# To get ADB: https://community.chocolatey.org/packages/adb
#
# Q: Why not a factory reset?
# A: https://www.reddit.com/r/Android/comments/naetg8/a_quick_powershell_script_for_clearing_user_data/gxtaswl?context=3
$confirmation = Read-Host "This will clear all packages data and user files. Are you sure you want to proceed? (y|n)"
if ($confirmation -ne 'y') {
return
@noseratio
noseratio / remove-unwanted-windows11-apps.ps1
Last active April 13, 2024 04:57
Windows 11 autorun resident apps that I have to remove manually
# Teams 2.0 (no work account support yet)
winget uninstall MicrosoftTeams_8wekyb3d8bbwe
# Your Phone
winget uninstall Microsoft.YourPhone_8wekyb3d8bbwe
# Widgets (Web Experience Pack)
winget uninstall MicrosoftWindows.Client.WebExperience_cw5n1h2txyewy
# Cortana
@noseratio
noseratio / reset-twitter-interest.md
Last active March 5, 2024 07:26
Reset Twitter interests
@noseratio
noseratio / RxWithCancellation.cs
Last active February 14, 2024 00:17
Cancelling an observable with a CancellationToken
// https://stackoverflow.com/q/72471152/1768303
// https://dotnetfiddle.net/bLYDgw
/*
I don't think I should be seeing "Emitting: 19" after "Cancelling"
Emitting: 18
TakeUntil passed: 18
OnNext: 18
Cancelling
@noseratio
noseratio / AsyncQueue.cs
Last active November 9, 2023 19:18
Simple async wrapper around .NET Queue
public sealed class AsyncQueue<T>: IAsyncDisposable
{
private readonly Queue<T> _queue = new();
private readonly SemaphoreSlim _semaphore = new(initialCount: 1, maxCount: 1);
private readonly CancellationTokenSource _cts = new();
private TaskCompletionSource _itemTcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
public async ValueTask<(bool, T)> TryPeekAsync(CancellationToken cancelToken)
{
await _semaphore.WaitAsync(cancelToken);
@noseratio
noseratio / DebugSyncContext.cs
Last active November 9, 2023 19:16
A simple helper SynchronizationContext to debug deadlocks
// A helper SynchronizationContext to debug deadlocks by @noseratio
// If you install DebugSyncContext at the very beginning of your console app and run it under debugger,
// it should stop where the deadlock is happening, with a better access to the stack frame.
using System.Diagnostics;
SynchronizationContext.SetSynchronizationContext(new DebugSyncContext());
Console.WriteLine("Hello!");
@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)
using System;
using System.Collections;
using System.Threading;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Collections.Generic;
namespace ConsoleApplication
{
public class Program
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
namespace ProductsApp.Controllers
{
// 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;