Skip to content

Instantly share code, notes, and snippets.

View ronnieoverby's full-sized avatar
🏠
Working from home

Ronnie Overby ronnieoverby

🏠
Working from home
  • Olo
  • Lexington, NC
View GitHub Profile
<script>
// loop over all "up-down" elements
for(let ud of document.querySelectorAll('span[id$=ud]'))
{
// reflect that it is already expanded
ud.className = 'arrow-up';
// derive the expandable element's id
let id = ud.id.substring(0, ud.id.length - 2);
@ronnieoverby
ronnieoverby / channels.cs
Last active March 11, 2020 12:48
An example when `Task.Yield()` is useful
var ch = Channel.CreateUnbounded<int>();
var producer = Task.Run(() =>
{
for (int i = 0; i < 500_000; i++)
ch.Writer.WriteAsync(i);
ch.Writer.Complete();
});
### 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 April 23, 2019 12:47
Reading references on value types vs. reference types.
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 April 23, 2019 12:47
Reading references on value types vs. reference types.
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
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)
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();
});
<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>
void Main()
{
var a = new BigDecimal(
BigInteger.Parse("9999999999999999999999999999999999999999999999999"), 0);
var b = new BigDecimal(
BigInteger.Parse("99999999999999999999998999999988998899999999999"),
17);
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)
{