Skip to content

Instantly share code, notes, and snippets.

🛠
Caffeinated

Joseph Musser jnm2

🛠
Caffeinated
Block or report user

Report or block jnm2

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jnm2
jnm2 / AsyncExtensions.cs
Created Dec 12, 2019
TaskScheduler.SwitchTo
View AsyncExtensions.cs
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
// Reference: https://github.com/microsoft/vs-threading/blob/v16.4.33/src/Microsoft.VisualStudio.Threading/AwaitExtensions.cs
internal static class AsyncExtensions
{
View Microsoft.PowerShell_profile.ps1
Import-Module 'C:\ProgramData\chocolatey\tools\poshgit\dahlbyk-posh-git-9bda399\src\posh-git.psd1'
if ((Get-Location).Path -eq $env:USERPROFILE) { cd $env:USERPROFILE\Source\Repos }
View CryptographicRandomSource.cs
using System;
using System.Runtime.Intrinsics.X86;
using System.Security.Cryptography;
public sealed class CryptographicRandomSource : IRandomSource, IDisposable
{
private readonly RandomNumberGenerator generator;
public CryptographicRandomSource()
{
View Refactor all tuples to pascal case.cs
using Microsoft.Build.Locator;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.MSBuild;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
View CommonUtils.TryGetCollectionCount.cs
using System;
using System.Collections;
using System.Collections.Generic;
public static class CommonUtils
{
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="enumerable"/> is <see langword="null"/>.
/// </exception>
public static bool TryGetCollectionCount<T>(IEnumerable<T> enumerable, out int count)
View CommonUtils.EnsureCapacity.cs
using System;
public static class CommonUtils
{
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when <paramref name="minCapacity"/> is less than zero.
/// </exception>
/// <exception cref="OutOfMemoryException">
/// Thrown when <paramref name="minCapacity"/> is greater than the maximum available array length.
/// </exception>
View ArrayBuilder.cs
using System;
/// <summary>
/// Enables building an array by setting indexes in any order without having to use an <c>Add</c> method.
/// </summary>
public struct ArrayBuilder<T>
{
private T[] array;
private int usedLength;
View AsyncParallelQueue.AtomicOperations.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
internal sealed partial class AsyncParallelQueue<T>
{
/// <summary>
/// <para>
/// The purpose of this class is to separate what must be done inside a lock (everything this class does) from
View OwnershipTracker.cs
using System;
using System.Threading;
/// <summary>
/// Provides an easy way handle situations where disposal is the current method's responsibility except on success.
/// For example, throwing before returning a disposable object may otherwise result in the disposable object never
/// being cleaned up.
/// </summary>
/// <example>
/// <code>
View ConditionalDisposer.cs
using System;
public struct ConditionalDisposer : IDisposable
{
private readonly IDisposable disposable;
private bool shouldDispose;
public ConditionalDisposer(IDisposable disposable)
{
this.disposable = disposable ?? throw new ArgumentNullException(nameof(disposable));
You can’t perform that action at this time.