Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Ronnie Overby ronnieoverby

🏠
Working from home
  • Olo
  • Lexington, NC
View GitHub Profile
@ronnieoverby
ronnieoverby / channels.cs
Last active Mar 11, 2020
An example when `Task.Yield()` is useful
View channels.cs
var ch = Channel.CreateUnbounded<int>();
var producer = Task.Run(() =>
{
for (int i = 0; i < 500_000; i++)
ch.Writer.WriteAsync(i);
ch.Writer.Complete();
});
View gist:06d0db3fa40a44af9effe4a56c19fbd8
### Keybase proof
I hereby claim:
* I am ronnieoverby on github.
* I am ronnieoverby (https://keybase.io/ronnieoverby) on keybase.
* I have a public key ASCXPI6o5jpbNT7RowJ7h_vBeGh0pzcksHwfhqWFQNVxUgo
To claim this, I am signing this object:
@ronnieoverby
ronnieoverby / gist:416183f553bc8a2399339742057ab220
Created Apr 23, 2019
Reading references on value types vs. reference types.
View gist:416183f553bc8a2399339742057ab220
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/value-types-and-reference-types
https://jonskeet.uk/csharp/references.html
http://www.albahari.com/valuevsreftypes.aspx
@ronnieoverby
ronnieoverby / gist:5d67fc7b4e18ad0c3e2d6c2e140ddddd
Created Apr 23, 2019
Reading references on value types vs. reference types.
View gist:5d67fc7b4e18ad0c3e2d6c2e140ddddd
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/value-types-and-reference-types
https://jonskeet.uk/csharp/references.html
http://www.albahari.com/valuevsreftypes.aspx
View BlockingStreams.cs
class BlockingStreams
{
public Stream WriteableStream { get; }
public Stream ReadableStream { get; }
private readonly CancellationToken _ct;
private readonly BlockingCollection<MemoryStream> _blocks;
public BlockingStreams(int? maxWrites = null, CancellationToken ct = default)
View BlockingCollectionExample.cs
var queue = new BlockingCollection<object>();
// ... meanwhile some other thread is adding to the queue
Task.Run(() =>
{
for (int i = 0; i < 10; i++)
queue.Add(i);
queue.CompleteAdding();
});
View GetQueryResult.linq
<Query Kind="Program">
<NuGetReference>Microsoft.CodeAnalysis.CSharp</NuGetReference>
<Namespace>LINQPad.ObjectModel</Namespace>
<Namespace>Microsoft.CodeAnalysis</Namespace>
<Namespace>Microsoft.CodeAnalysis.CSharp</Namespace>
<Namespace>Microsoft.CodeAnalysis.Emit</Namespace>
<Namespace>static LINQPad.Util</Namespace>
<Namespace>static System.IO.Path</Namespace>
<Namespace>static System.Reflection.Assembly</Namespace>
<Namespace>static System.Reflection.BindingFlags</Namespace>
View alig.cs
void Main()
{
var a = new BigDecimal(
BigInteger.Parse("9999999999999999999999999999999999999999999999999"), 0);
var b = new BigDecimal(
BigInteger.Parse("99999999999999999999998999999988998899999999999"),
17);
View AttachmentExtensions.cs
public static class AttachmentExtensions
{
private static readonly ConditionalWeakTable<object, ConcurrentDictionary<string, object>> _attachmentTable =
new ConditionalWeakTable<object, ConcurrentDictionary<string, object>>();
/// <summary>
/// Atomically gets or sets an attached value if it's found.
/// </summary>
public static AttachmentResult<T> GetOrSetAttached<T>(this object host, Func<T> factory, string key = null)
{
@ronnieoverby
ronnieoverby / MyExtensions.cs
Created Oct 21, 2016
Mitigates Linqpad DumpContainer MemoryDump
View MyExtensions.cs
public static class MyExtensions
{
public static void UpdateContentOccasionally(this DumpContainer dc, object newContent, int intervalMilliseconds = 1000) =>
UpdateContentOccasionally(dc, newContent, TimeSpan.FromMilliseconds(intervalMilliseconds));
public static void UpdateContentOccasionally(this DumpContainer dc, object newContent, TimeSpan interval)
{
var swAttachment = dc.GetOrSetAttached(() => Stopwatch.StartNew());