Skip to content

Instantly share code, notes, and snippets.

View jnm2's full-sized avatar
🧬
Evolving

Joseph Musser jnm2

🧬
Evolving
View GitHub Profile
declare @schemaName sysname = 'dbo'
declare @tableName sysname = 'ItemPrices'
declare @rowCondition nvarchar(max) = 'PriceCode in (''SEEDS'', ''YEAREND'')'
declare @builder nvarchar(max);
select @builder = coalesce(@builder + '
', '') + 'if exists(
select *' + QueryWithoutSelect + ')
@jnm2
jnm2 / Collection interfaces.md
Last active October 2, 2023 19:27
.NET collection interfaces
flowchart
    ICollection --- IEnumerable
    IList --- ICollection
    IEnumerableT[IEnumerable<T>] --- IEnumerable
    ICollectionT[ICollection<T>] --- IEnumerableT
    IListT[IList<T>] --- ICollectionT
    IReadOnlyCollectionT[IReadOnlyCollection<T>] --- IEnumerableT
    IReadOnlyListT[IReadOnlyList<T>] --- IReadOnlyCollectionT
/// <summary>
/// Tracks how many references there are to a disposable object, and disposes it when there are none remaining.
/// </summary>
public sealed class RefCountingDisposer
{
private readonly IDisposable disposable;
private uint refCount = 1;
private readonly object lockObject = new();
/// <summary>
using System;
using System.Threading;
internal sealed class DeferredAction
{
private static readonly Action SentinelNextSetShouldPost = () => { };
private readonly SynchronizationContext synchronizationContext;
private Action scheduledAction = SentinelNextSetShouldPost;
#if !NET7_0_OR_GREATER
namespace System.Runtime.CompilerServices;
#endif
#if !NET5_0_OR_GREATER
internal static class IsExternalInit { }
#endif
#if !NET7_0_OR_GREATER
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Struct, Inherited = false)]
@jnm2
jnm2 / Open types in nameof.md
Last active October 8, 2023 20:54
Open types in nameof

Open types in nameof

[TODO: follow standard sections, add examples, flesh everything out]

Motivation

This is a small feature that removes a common frustration: why do I have to pick a generic type argument when the choice has no effect on the evaluation of the expression? It's very odd to require something to be specified within an operand when it has no impact on the result. Notably, typeof does not suffer from this limitation.

It's not just about code that better expresses itself. Once some arbitrary type argument has been chosen in a nameof expression, such as object?, changing a constraint on a type parameter can break uses of nameof unnecessarily. Insult becomes added to injury in this scenario. Satisfying the type parameter requires declaring a dummy class to implement an interface which is constraining the type parameter. Now there's unused metadata and a strange name invented, all for the purpose of adding a type argument to the nameof expression, a type argument which `na

Get-NetNeighbor -AddressFamily IPv4 |
Select-Object -ExpandProperty IPAddress -Unique |
ForEach-Object -ThrottleLimit 20 -Parallel {
try {
(Resolve-DnsName $_ -LlmnrNetbiosOnly -ErrorAction Stop).NameHost
} catch { }
}
using System.Reflection;
using System.Reflection.Emit;
public static class CommandVerifier
{
private static readonly AsyncLocal<Action<object?[]>?> ActiveInterceptor = new();
private static readonly FieldInfo ActiveInterceptorField = typeof(CommandVerifier).GetField(nameof(ActiveInterceptor), BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly)!;
public static async Task<object?[]> VerifyArgumentsAsync(Func<Task> invokeInterceptedDelegateAsync)
{
using System;
using System.Reflection;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands;
[AttributeUsage(AttributeTargets.Method)]
public sealed class SeedAttribute : Attribute, IWrapSetUpTearDown
{
public SeedAttribute(int randomSeed)
using System;
using System.Globalization;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands;
public sealed class EffectiveAttribute : NUnitAttribute, IWrapSetUpTearDown
{
private readonly DateTime starting;