Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Ikiru Yoshizaki guitarrapc

:octocat:
View GitHub Profile
@guitarrapc
guitarrapc / gprc_build.md
Last active Mar 26, 2021
gprc/grpc をソースビルドするための覚書
View gprc_build.md

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 Mar 17, 2021
Easing functions
View Easing.cs
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 Mar 16, 2021
Calculate Histogram for TimeSpans
View Histogram.cs
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 Mar 16, 2021
Calculate Latency distibutions
View LatencyDistribution.cs
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 Mar 8, 2021
Selected pool size execution pool.
View Program.cs
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 Mar 8, 2021
Convert 1d1h1m1s format to TimeSpan, and viceversa.
View Durations.cs
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();
View docker-compose.yaml
version: "3"
services:
mysql:
image: mysql:5.7.12
ports:
- 3506:3306
environment:
MYSQL_ROOT_PASSWORD: root
@guitarrapc
guitarrapc / StringBenchmark.cs
Created Feb 27, 2021
Benchmark dotnet with string -> string, and object -> string
View StringBenchmark.cs
void Main()
{
var summary = BenchmarkRunner.Run<StringOutput>();
}
[SimpleJob(RuntimeMoniker.NetCoreApp30, baseline: true)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
[RPlotExporter]
[MemoryDiagnoser]
public class StringOutput
@guitarrapc
guitarrapc / ForceDeleteAllVersionObject.cs
Created Feb 11, 2021
Force delete your versioned s3 object from bucket
View ForceDeleteAllVersionObject.cs
async Task Main()
{
var client = new Amazon.S3.AmazonS3Client();
var bucket = "YOUR_BUCKET";
ListVersionsResponse response = null;
var count = 0;
do
{
var keyVersions = new List<KeyVersion>();
response = await client.ListVersionsAsync(new ListVersionsRequest
@guitarrapc
guitarrapc / user-data.sh
Last active Jan 27, 2021
Amazon Linux2 UserData to add Ec2 Instance to the CloudMap NameSpace Service. based on https://www.appmeshworkshop.com/appendix/servicediscovery/
View user-data.sh
#!/bin/bash -ex
SERVICE_ID="your_service_map_id"
INSTANCE_PORT="80"
yum update -y && yum install -y jq
EC2_METADATA=http://169.254.169.254/latest
REGION=$(curl -s $EC2_METADATA/dynamic/instance-identity/document | jq -r '.region')
INSTANCE_ID=$(curl -s $EC2_METADATA/meta-data/instance-id);
INSTANCE_IP=$(curl -s $EC2_METADATA/meta-data/local-ipv4);