Skip to content

Instantly share code, notes, and snippets.

View jnm2's full-sized avatar
🧬
Evolving

Joseph Musser jnm2

🧬
Evolving
View GitHub Profile
// Csproj: <PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.588-beta" PrivateAssets="all" />
// NativeMethods.txt: GetLastInputInfo
using System;
using System.Threading;
using Windows.Win32;
using Windows.Win32.UI.KeyboardAndMouseInput;
public sealed class InactivityWatcher : IDisposable
{
@jnm2
jnm2 / LICENSE.txt
Last active April 28, 2024 19:07
StreamingZipReader proof of concept for https://github.com/dotnet/runtime/issues/59027
MIT License
Copyright (c) 2021 Joseph Musser
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
using Microsoft.Win32.SafeHandles;
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
internal static class AlternateDataStream
{
/// <summary>
/// <para>
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
public static class GuaranteedCleanup
{
private static readonly ManualResetEventSlim CleanupFinished = new();
private static readonly CancellationTokenSource ShutdownStarted = new();
private static int cleanupTaskCount;
using System;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Guarantees that a <see cref="Func{T1, TResult}"/> will never be invoked more than once.
/// </summary>
public sealed class OneTimeTask<T1, TResult>
{
private Func<T1, TResult>? resultFactory;
using System;
using System.Diagnostics;
/// <summary>
/// Defers <see cref="decimal"/> division so that intermediate results such as 1/3 can later be combined with other
/// results such as multiplying by 3 to obtain a lossless final result of <c>1</c> rather than <c>0.99999…</c>.
/// </summary>
[DebuggerDisplay("{" + nameof(ToString) + "(),nq}")]
public readonly struct DecimalRational : IEquatable<DecimalRational>, IComparable<DecimalRational>
{
$youtubeDl = Join-Path $PSScriptRoot 'youtube-dl.exe'
$ffmpeg = Join-Path $PSScriptRoot 'ffmpeg.exe'
$ErrorActionPreference = 'Stop'
if (-not (Test-Path $youtubeDl)) {
Write-Host 'Downloading youtube-dl...'
Invoke-WebRequest 'https://youtube-dl.org/downloads/latest/youtube-dl.exe' -OutFile $youtubeDl
}
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using System;
using System.IO;
using System.IO.Enumeration;
using System.Linq;
var searchPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @"Source\Repos");
using System.IO;
namespace Techsola.InstantReplay
{
partial class GifWriter
{
private struct GifImageDataChunker
{
const byte MaxChunkLength = 255;
using System;
using System.Linq;
using Microsoft.CodeAnalysis;
internal static class INamespaceOrTypeSymbolExtensions
{
/// <summary>
/// Checks the full name of a type or namespace without incurring the expense of building a full name string.
/// </summary>
public static bool HasFullName(this INamespaceOrTypeSymbol symbol, params string[] segments)