Skip to content

Instantly share code, notes, and snippets.

View guitarrapc's full-sized avatar
:octocat:

Ikiru Yoshizaki guitarrapc

:octocat:
View GitHub Profile
void Main()
{
var p1 = new Position { X = 2, Y = 0, };
var p2 = new Position { X = 1, Y = 2, };
var p3 = new Position();
var p4 = new Position { X = 5, Y = 10, };
var p5 = new Position { X = 50, };
var p6 = new Position { Y = -10, };
G(p1).Dump(); // 2
G(p2).Dump(); // 0
void Main()
{
var hoge = GetHoge();
}
public IEnumerable<IHoge> GetHoge()
{
var hoge = Enumerable.Range(0, 1).Select(x => new Hoge());
return hoge;
}
@guitarrapc
guitarrapc / gprc_build.md
Last active March 18, 2022 02:38
gprc/grpc をソースビルドするための覚書

grpc/grpc をSource ビルドするメモ

ビルドする場合の事前作業

Windows

  • Grpc.Core や Grpc.Core.Api のみならこれだけでok
    • .NET Core SDK のインストール
    • VSビルドする場合、VS2019、.NET Framework 4.6.2 targeting pack をインストール
  • csharp_ext だと、cmake か ninja あるいは bazel ビルドが必要。
@guitarrapc
guitarrapc / Easing.cs
Created March 17, 2021 06:58
Easing functions
public static class Easing
{
public static double Linear(double currentTime, double startValue, double changeValue, double duration) => changeValue * currentTime / duration + startValue;
// Quadratic (x2)
public static double InQuadratic(double currentTime, double startValue, double changeValue, double duration)
{
currentTime /= duration;
return changeValue * Math.Pow(currentTime, 2) + startValue;
}
@guitarrapc
guitarrapc / Histogram.cs
Last active March 16, 2021 15:09
Calculate Histogram for TimeSpans
void Main()
{
var random = new Random();
var data = Enumerable.Range(0, 10000)
.Select(x => TimeSpan.FromMilliseconds(random.Next(1, 500)))
.OrderBy(x => x)
.ToArray();
var fastest = data[0];
var slowest = data[^1];
@guitarrapc
guitarrapc / LatencyDistribution.cs
Created March 16, 2021 14:46
Calculate Latency distibutions
void Main()
{
var random = new Random();
var data = Enumerable.Range(0, 10000)
.Select(x => TimeSpan.FromMilliseconds(random.Next(1, 500)))
.OrderBy(x => x)
.ToArray();
Latencies(data).Dump();
}
@guitarrapc
guitarrapc / Program.cs
Last active March 8, 2021 18:48
Selected pool size execution pool.
async Task Main()
{
var sw = Stopwatch.StartNew();
// pool size = 50, runnning for 20sec
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20));
using var pool = new TaskPool<int>(50, cts.Token);
while (!cts.Token.IsCancellationRequested)
{
pool.RegisterAsync(() => SendAsync(1)).FireAndForget();
}
@guitarrapc
guitarrapc / Durations.cs
Last active March 8, 2021 14:52
Convert 1d1h1m1s format to TimeSpan, and viceversa.
void Main()
{
Durations.FromString("10d").Dump();
Durations.FromString("10h").Dump();
Durations.FromString("10m").Dump();
Durations.FromString("10s").Dump();
Durations.FromString("100d10h10m10s").Dump();
Durations.FromString("100d10h10s").Dump();
Durations.FromString("0").Dump();
version: "3"
services:
mysql:
image: mysql:5.7.12
ports:
- 3506:3306
environment:
MYSQL_ROOT_PASSWORD: root
@guitarrapc
guitarrapc / StringBenchmark.cs
Created February 27, 2021 23:11
Benchmark dotnet with string -> string, and object -> string
void Main()
{
var summary = BenchmarkRunner.Run<StringOutput>();
}
[SimpleJob(RuntimeMoniker.NetCoreApp30, baseline: true)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
[RPlotExporter]
[MemoryDiagnoser]
public class StringOutput