Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin Gosse kevingosse

View GitHub Profile
View ApiWebRequestFactoryTests.cs
/// <summary>
/// This test ensures that the ApiWebRequestFactory behaves correctly when
/// a different type of WebRequest is assigned to the http:// prefix
/// </summary>
[Fact]
public void OverrideHttpPrefix()
{
// Couldn't find a way to "officially" unregister a prefix but that shouldn't stop us
var prefixListProperty = typeof(WebRequest).GetProperty("PrefixList", BindingFlags.Static | BindingFlags.NonPublic);
var oldPrefixList = prefixListProperty.GetValue(null);
View ApiWebRequestFactory.cs
internal class ApiWebRequestFactory : IApiRequestFactory
{
public IApiRequest Create(Uri endpoint)
{
return new ApiWebRequest(WebRequest.CreateHttp(endpoint));
}
}
View Program.cs
WebRequest.RegisterPrefix("http://", new CustomWebRequestFactory());
View ApiWebRequestFactory.cs
internal class ApiWebRequestFactory : IApiRequestFactory
{
public IApiRequest Create(Uri endpoint)
{
return new ApiWebRequest((HttpWebRequest)WebRequest.Create(endpoint));
}
}
View StartupAssemblyLoadContext.cs
class StartupAssemblyLoadContext : AssemblyLoadContext
{
private readonly AssemblyDependencyResolver _resolver;
public StartupAssemblyLoadContext()
{
_resolver = new AssemblyDependencyResolver(Assembly.GetExecutingAssembly().Location);
}
protected override Assembly Load(AssemblyName assemblyName)
View StartupHook.cs
public static void Initialize()
{
var loadContext = new StartupAssemblyLoadContext();
var assembly = loadContext.LoadFromAssemblyName(new AssemblyName("GCCollector"));
assembly.CreateInstance("GCCollector.Poller");
}
View StartupHook.cs
internal class StartupHook
{
public static void Initialize()
{
new Thread(PollGCMetrics)
{
IsBackground = true,
Name = "GCMetricsPoller"
}.Start();
}
View SingleThreadedSynchronizationContext.cs
public class SingleThreadedSynchronizationContext : SynchronizationContext
{
private Thread _thread;
private BlockingCollection<Action> _queue = new BlockingCollection<Action>();
public SingleThreadedSynchronizationContext()
{
_thread = new Thread(() =>
{
View hook.cs
using System;
using System.IO;
using System.Text;
internal class StartupHook
{
public static void Initialize()
{
Console.SetOut(new FixCasingTextWriter(Console.Out));
}
View checkGCKeywords.sh
#!/bin/bash
offset="0x"$(nm -C $2/libcoreclr.so | grep GCEventStatus::enabledLevels | cut -d ' ' -f1)
module="0x"$(cat /proc/$1/maps | grep -m 1 libcoreclr.so | cut -d '-' -f1)
dd bs=1 skip="$(($module + $offset))" count=8 status=none if="/proc/$1/mem" | od -An -vtu4
You can’t perform that action at this time.