Skip to content

Instantly share code, notes, and snippets.

View itn3000's full-sized avatar
πŸ€”
πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”

Yusuke Ito itn3000

πŸ€”
πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”
View GitHub Profile
@itn3000
itn3000 / GetConfigurationChangedNotification.cs
Last active March 29, 2022 16:41
sandbox for getting notification of IConfiguration changes
// dotnet add package Microsoft.Extensions.Hosting;
// dotnet add package System.Reactive;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Configuration;
using System.Reactive.Concurrency;
using System.Reactive.Subjects;
using System.Reactive.Linq;
using System.CommandLine;
using System.CommandLine.Binding;
var opt1 = new Option<string>(new string[]{ "--opt1", "-o1" }, "this is option1");
var opt2 = new Option<int>(new string[]{ "--opt2", "-o2" }, "this is option2");
var rootcmd = new RootCommand("this is root");
rootcmd.Add(opt1);
rootcmd.Add(opt2);
rootcmd.AddCommand(CreateCommand1());
@itn3000
itn3000 / versionreadfrompe.rs
Last active March 24, 2022 02:32
read exe version by rust with pelite( https://github.com/CasualX/pelite )
// this works with linux
use std::fs;
use pelite::pe64::Pe;
use pelite::pe32::Pe as Pe32;
use pelite::Error as PeErrors;
use memmap2::Mmap;
fn output_ver_info(p: &std::path::Path) -> Result<(), anyhow::Error> {
{
// let f = std::fs::File::open(p)?;
@itn3000
itn3000 / FasterLogV2PreTest.cs
Created March 8, 2022 17:54
FasterLog v2pre sandbox
using FASTER.core;
using var x = Devices.CreateLogDevice("xlog");
var flsetting = new FasterLogSettings("hoge");
using var fl = new FasterLog(new FasterLogSettings("hoge")
// {
// FastCommitMode = true,
// LogCommitDir = "xlog-commits"
// }
);
@itn3000
itn3000 / RateLimitApiTest.cs
Last active April 27, 2022 04:32
memo about System.Threading.RateLimiting(Japanese)
// See https://aka.ms/new-console-template for more information
using System.Threading.RateLimiting;
using System.Diagnostics;
await Concurrency();
// await TokenBucket();
async Task Concurrency()
{
await using var limiter = new ConcurrencyLimiter(new ConcurrencyLimiterOptions(
@itn3000
itn3000 / SerializeErrorInSystemJson.cs
Last active February 16, 2022 07:22
Serialize error in System.Text.Json if ctor has "in" or "ref" keyword
// TargetFramework: net6.0
// this can be avoided if there is ctor with no "ref" or "in".
using System.Text.Json;
int z = 0;
var c1 = new C1(ref z);
try
{
JsonSerializer.Serialize(c1);
}
@itn3000
itn3000 / FasterLogExporter.cs
Last active February 16, 2022 06:31
opentelemetry-dotnet FasterLog exporter(test implementation)
using OpenTelemetry.Trace;
using OpenTelemetry.Resources;
using OpenTelemetry;
using FASTER.core;
using System.Text.Json;
using System.Buffers;
using System.Diagnostics;
using OpenTelemetry.Metrics;
namespace opentelemetryfltest
@itn3000
itn3000 / MessagePipeUnixDomainSocketTest.cs
Last active September 21, 2022 11:37
MessagePipe Unix domain socket example
// you can run this code in Linux,macOS,Windows(10 April 2018 or later)
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using System;
using MessagePipe;
public class RemotePublisher : BackgroundService
{
IDistributedPublisher<int, int> _Publisher;
@itn3000
itn3000 / FileDeletedWithFasterLog.cs
Last active January 11, 2022 00:11
old file did not deleted in FasterLog
using FASTER.core;
// all old files are deleted after truncating in same session
{
using var device = Devices.CreateLogDevice("test.log", recoverDevice: true);
using var log = new FasterLog(new FasterLogSettings()
{
LogDevice = device,
SegmentSizeBits = 20,
MemorySizeBits = 15,
PageSizeBits = 10,
@itn3000
itn3000 / InstrumentToEventCounter.cs
Last active November 26, 2021 07:51
Example code for treating System.Diagnostics.Metrics as EventCounter(for dotnet-counters)
using System.Collections.Concurrent;
using System.Diagnostics.Metrics;
using System.Diagnostics.Tracing;
using var cts = new CancellationTokenSource();
using var meter = new Meter("m1");
using var counterCollector = new CounterCollector(MyEventSource.Log);
var c1 = meter.CreateCounter<int>("metric-counter");
counterCollector.AddCounter(c1);