Skip to content

Instantly share code, notes, and snippets.

View StephenCleary's full-sized avatar

Stephen Cleary StephenCleary

View GitHub Profile
@StephenCleary
StephenCleary / memory_docs_samples.md
Created September 14, 2023 12:41 — forked from GrabYourPitchforks/memory_docs_samples.md
Memory<T> API documentation and samples

Memory<T> API documentation and samples

This document describes the APIs of Memory<T>, IMemoryOwner<T>, and MemoryManager<T> and their relationships to each other.

See also the Memory<T> usage guidelines document for background information.

First, a brief summary of the basic types

  • Memory<T> is the basic type that represents a contiguous buffer. This type is a struct, which means that developers cannot subclass it and override the implementation. The basic implementation of the type is aware of contigious memory buffers backed by T[] and System.String (in the case of ReadOnlyMemory<char>).
@StephenCleary
StephenCleary / async.cs
Last active February 9, 2017 11:54 — forked from davidfowl/async.cs
Async quiz: How many threads are used? What does it print?
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
// The more evil version. :)
class Program
{
static void Main(string[] args)
{
internal class AwaitableMessages
{
public static Task<T> NextMessageAsync<T>()
{
var tcs = new TaskCompletionSource<T>();
Messenger.Default.Register<T>(null, item => tcs.TrySetResult(item));
return tcs.Task;
}
}
// I'm starting 10 calls at every 50 msec. Each call has a random execution time between 1-19 seconds.
// Many times the last answer comes from the 9th call instead of the 10th.
// I'm not sure I'm testing it properly.
void Main()
{
var rand = new Random();
Enumerable.Range(1,10)
@StephenCleary
StephenCleary / LinkedDic.cs
Last active December 31, 2015 04:09 — forked from ayende/LinkedDic.cs
Added tests with Builder, SortedImmutableDictionary, and LinkedDictionaryUnoptimized.
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Voron.Util
{
public class LinkedDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IReadOnlyDictionary<TKey, TValue>
where TValue : class, new()
{
private readonly TValue _deleteMarker = new TValue();
@StephenCleary
StephenCleary / gist:6794708
Last active December 24, 2015 11:59 — forked from anonymous/gist:6782497
500 Internal Server Error for the request "https://www.healthcare.gov/ee-rest/ffe/en_US/MyAccountEIDMUnsecuredIntegration/fetchAllSecurityQuestions/ffm" which is silently ignored by the JavaScript and results in no security questions in the dropdowns. Site has been down 34.5 hours and counting... The error message has been updated today with pre…
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: Could not send Message.
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:110)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:323)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:126)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:113)