Skip to content

Instantly share code, notes, and snippets.

View ReubenBond's full-sized avatar
🌞
building

Reuben Bond ReubenBond

🌞
building
View GitHub Profile
@ReubenBond
ReubenBond / FrequencyFilter.cs
Created April 13, 2024 23:07
Filtered Space-Saving
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Orleans.Runtime.Placement.Rebalancing;
// Implementation of "Filtered Space-Saving" from "Finding top-k elements in data streams"
// by Nuno Homem & Joao Paulo Carvalho (https://www.hlt.inesc-id.pt/~fmmb/references/misnis.ref0a.pdf).
internal abstract class FrequencyFilter<TKey>(int capacity) where TKey : notnull
{
@ReubenBond
ReubenBond / ConcurrentLruGrainDirectoryCache.cs
Last active April 5, 2024 22:10
BitFaster.Caching Orleans IGrainDirectoryCache implementation
using BitFaster.Caching;
using BitFaster.Caching.Lru;
using Microsoft.Extensions.Options;
using Orleans.Configuration;
using Orleans.Runtime;
using Orleans.Runtime.GrainDirectory;
using System.Diagnostics.CodeAnalysis;
namespace Orleans.BitFasterCaching.GrainDirectoryCache;
@ReubenBond
ReubenBond / LongRunningReminderGrain.cs
Created January 17, 2024 16:46
Orleans Grain Long Running Reminder
#nullable enable
using Orleans.Runtime;
namespace MyGrains;
public class MyLongRunningReminderGrain : Grain, IRemindable
{
private readonly CancellationTokenSource _shutdownCancellation = new();
private Task? _backgroundTask;
@ReubenBond
ReubenBond / CpuUsage.cs
Created January 17, 2024 16:45
.NET CPU Usage EventCounter
using System.Diagnostics.Tracing;
using System.Security.Cryptography;
using System.Text;
public class Program
{
public static void Main(string[] args)
{
var listener = new SystemRuntimeEventCounterListener();
Task.Run(async () =>
{
"name": "Dactyl Manuform (5x7)",
"vendorProductId": 1145910583,
"macros": [
"{KC_LCTL,KC_LEFT}",
"{KC_LCTL,KC_DOWN}",
"{KC_LCTL,KC_UP}",
"{KC_LCTL,KC_RGHT}",
"",
"",
@ReubenBond
ReubenBond / HostedServiceCommunicationListener.cs
Last active December 1, 2022 21:10
Service Fabric IHostBuilder integration
namespace YOUR_NAMESPACE
{
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
/// <summary>
/// Service Fabric <see cref="ICommunicationListener"/> which integrates with an <see cref="IHost"/> instance.
@ReubenBond
ReubenBond / ObserverWithReturn.csproj
Created March 20, 2022 19:36
Orleans grain observer (IGrainObserver) which returns results
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>ObserverWithReturn</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Ready
****** START compiling Hagar.Buffers.Reader`1[ReadOnlySequence`1][System.Buffers.ReadOnlySequence`1[System.Byte]]:ReadByte():ubyte:this (MethodHash=011f4f14)
Generating code for Windows x64
OPTIONS: compCodeOpt = BLENDED_CODE
OPTIONS: compDbgCode = true
OPTIONS: compDbgInfo = true
OPTIONS: compDbgEnC = false
OPTIONS: compProcedureSplitting = false
OPTIONS: compProcedureSplittingEH = false
IL to import:

Recommendations:

@ReubenBond
ReubenBond / killall.ps1
Last active May 20, 2020 18:33
killall cmd for PowerShell with completion
# In a PS terminal, type "code $profile" and put this in there
function killall {
param(
[ArgumentCompleter(
{
param($cmd, $param, $values)
get-process |
? { $_.Name.StartsWith($values, [StringComparison]::OrdinalIgnoreCase) } |