Skip to content

Instantly share code, notes, and snippets.

View SimonCropp's full-sized avatar

Simon Cropp SimonCropp

View GitHub Profile
@SimonCropp
SimonCropp / cs
Last active December 22, 2023 01:58
StringBuilder AsSpan
#if NET8_0_OR_GREATER
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "m_ChunkPrevious")]
private static extern ref StringBuilder? ChunkPrevious(StringBuilder builder);
static bool HasSingleChunk(this StringBuilder builder) =>
ChunkPrevious(builder) == null;
#endif
public static CharSpan AsSpan(this StringBuilder builder)
{
@SimonCropp
SimonCropp / Enabling_OSS_sustainability.md
Last active January 3, 2021 18:51
Enabling OSS sustainability

Add "requesting sponsorship" to package metadata

Package formats (nuget, npm etc) should be amended to add the concept of "this package is requesting sponsorship via ...". The "via..." part could be influence by the GitHub Funding.yml convention.

Surface "requesting sponsorship" in tooling

Once "requesting sponsorship" metadata is added, tooling can expose this in a variety of ways. For example:

The case for disabling GH Issues

Disclaimer: This is a personal perspective. The majority of OSS projects I contribute to are libraries and developer tooling. The side effect of this is that if a person is using one of these projects, they have the expertise to understand and modify the code of the project. Also many of the comments made are from my experience, your experience may vary.

The problem with GitHub Issues

Too generic

var props = typeof(DateTimeFormatInfo).GetProperties();
var value = new DateTime(2012, 5, 28, 11, 35, 0);
var builder = new StringBuilder();
foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
builder.AppendLine(culture.DisplayName);
var info = culture.DateTimeFormat;
foreach (var prop in props)
{
@SimonCropp
SimonCropp / Consider-not-using-namespaces.md
Last active January 18, 2020 18:30
Consider not using namespaces

Over the years C# has been criticised for being too verbose. This is especially common when compared to languages like Scala, FSharp, Erlang, Ruby and Javascript. There is no arguing that the syntactic constructs in these languages allow for a much terser coding style. However C# can be more succinct than people realize.

So with the idea that "less code is better code", what can be changed about how we code C#?

There are a few solutions, for now, I'm going to focus on:

Consider NOT using namespaces

This might sound crazy but bear with me.

@SimonCropp
SimonCropp / OpenSolution.cmd
Created December 3, 2019 05:09
Fork: Open in VS
cd %1
powershell -executionpolicy remotesigned -file c:\code\opensolution.ps1 -nologo
<entry>
<record>678</record>
<time>2019/04/16 02:40:55.883</time>
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.NullReferenceException: Object reference not set to an instance of an object.&#x000D;&#x000A;
at ShaneBlazek.DisableRegions.RegionLineTaggerProvider.CreateTagger[T](ITextView textView, ITextBuffer buffer)&#x000D;&#x000A;
at Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator`1.InstantiateViewTagger(ITextView textView, Lazy`2 factory, ITextBuffer textBuffer, IList`1 newTaggers)&#x000D;&#x000A;---
End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;
# Result Protocol Host URL Body Caching Content-Type Process Comments Custom
1 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.nlog.fody/index.json 7,002 no-store application/json devenv:7312
2 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.log4net.fody/index.json 6,884 no-store application/json devenv:7312
3 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.commonlogging.fody/index.json 5,619 no-store application/json devenv:7312
4 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/xunit.runner.visualstudio/index.json 5,009 no-store application/json devenv:7312
5 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.catel.fody/index.json 5,825 no-store application/json devenv:7312
6 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.nservicebus.fody/index.json 3,839 no-store application/json devenv:7312
7 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.serilog.fody/index.json 7,368 no-store application/json devenv:7312
8 20
# Result Protocol Host URL Body Caching Content-Type Process Comments Custom
1 200 HTTPS api-v2v3search-0.nuget.org /query?q=&skip=0&take=26&prerelease=false&supportedFramework=.NETFramework,Version=v4.7.2&semVerLevel=2.0.0 20,887 no-cache; Expires: 0 application/json devenv:7312
2 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.nlog.fody/index.json 7,002 no-store application/json devenv:7312
3 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.log4net.fody/index.json 6,884 no-store application/json devenv:7312
4 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.catel.fody/index.json 5,825 no-store application/json devenv:7312
5 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/xunit.runner.visualstudio/index.json 5,009 no-store application/json devenv:7312
6 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.custom.fody/index.json 5,626 no-store application/json devenv:7312
7 200 HTTPS api.nuget.org /v3/registration3-gz-semver2/anotar.commonloggin
# Result Protocol Host URL Body Caching Content-Type Process Comments Custom
59 200 HTTP Tunnel to api.nuget.org:443 0 devenv:7312
60 200 HTTP Tunnel to api.nuget.org:443 0 devenv:7312
61 200 HTTP Tunnel to api.nuget.org:443 0 devenv:7312
62 200 HTTP Tunnel to api.nuget.org:443 0 devenv:7312
63 200 HTTP Tunnel to api.nuget.org:443 0 devenv:7312
64 200 HTTP Tunnel to api.nuget.org:443 0 devenv:7312
65 200 HTTP Tunnel to api.nuget.org:443 0 devenv:7312
66 200 HTTP Tunnel to api.nuget.org:443 0 devenv:7312
67 200 HTTP Tunnel to api.nuget.org:443 0 devenv:7312