Skip to content

Instantly share code, notes, and snippets.

View daveaglick's full-sized avatar

Dave Glick daveaglick

View GitHub Profile
@daveaglick
daveaglick / StringStream.cs
Last active January 7, 2021 02:12
Sample StringStream Implementation
public class StringStream : Stream
{
private const int DefaultBufferCharCount = 256; // The number of characters to buffer at a time
private readonly Encoding _encoding;
private readonly int _bufferCharCount;
private Memory<byte> _outputBuffer;
private Encoder _encoder;
private ReadOnlyMemory<char> _pendingSource;
private Memory<byte> _pendingOutput;
@daveaglick
daveaglick / ChangeLevelLoggerProvider.cs
Created November 20, 2020 16:47
Intercepting log messages with a wrapping logger provider
public class ChangeLevelLoggerProvider : InterceptingLoggerProvider
{
private readonly Func<LogLevel, LogLevel> _changeLevel;
public ChangeLevelLoggerProvider(ILoggerProvider provider, Func<LogLevel, LogLevel> changeLevel)
: base(provider)
{
_changeLevel = changeLevel ?? throw new ArgumentNullException(nameof(changeLevel));
}
@daveaglick
daveaglick / statiq-cla.md
Last active May 15, 2021 09:27
Statiq Contributor Agreement

Contributor Agreement - Individual Contributor Non-Exclusive License Agreement

Thank you for your interest in contributing to Statiq ("We" or "Us").

The purpose of this contributor agreement ("Agreement") is to clarify and document the rights granted by contributors to Us.

How to use this Contributor Agreement

If You are an employee and have created the Contribution as part of your employment, You need to have Your employer approve this Agreement. If You do not own the Copyright in the entire work of authorship, any other author of the Contribution should also sign this – in any event, please contact Us at statiq@statiq.dev.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace DocumentQuery
Hello from the Statiq docs!
@daveaglick
daveaglick / feedly.opml
Created November 14, 2017 14:41
Feedly OPML
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Dave subscriptions in feedly Cloud</title>
</head>
<body>
<outline text="Development" title="Development">
<outline type="rss" text="Scott Hanselman" title="Scott Hanselman" xmlUrl="http://feeds.feedburner.com/ScottHanselman" htmlUrl="https://www.hanselman.com/blog/"/>
<outline type="rss" text="Cetus" title="Cetus" xmlUrl="https://feeds.feedburner.com/cetus/fVRw" htmlUrl="https://cetus.io/"/>
@daveaglick
daveaglick / changeconfig.cs
Created August 22, 2017 11:15
Change config file at runtime
// Set app.config - http://stackoverflow.com/a/6151688/807064
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"C:\new.config");
typeof(ConfigurationManager)
.GetField("s_initState", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, 0);
typeof(ConfigurationManager)
.GetField("s_configSystem", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, null);
typeof(ConfigurationManager).Assembly.GetTypes()
.Where(x => x.FullName == "System.Configuration.ClientConfigPaths")
@daveaglick
daveaglick / refextensions.cs
Created August 16, 2017 20:50
An example use case of ref extensions for immutable objects
using System;
public class Program
{
public void Main()
{
Foo foo = new Foo();
// Update with method chaining
// and self assignment,
@daveaglick
daveaglick / poll.png
Last active May 18, 2017 16:12
Braces
poll.png

Keybase proof

I hereby claim:

  • I am daveaglick on github.
  • I am daveaglick (https://keybase.io/daveaglick) on keybase.
  • I have a public key whose fingerprint is 20E2 FB65 377E D104 FD1C CE61 E0DE 5630 92FE 2979

To claim this, I am signing this object: