Skip to content

Instantly share code, notes, and snippets.

:octocat:

Ikiru Yoshizaki guitarrapc

:octocat:
Block or report user

Report or block guitarrapc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@guitarrapc
guitarrapc / GenerateTerraform_GuardDuty.cs
Last active Mar 5, 2020
generate terraform guardduty for all region via C# template. (member account is not scoped)
View GenerateTerraform_GuardDuty.cs
void Main()
{
var awsProviderVersion = "2.51.0";
GenProviders().Dump();
GenModules().Dump();
static string[] GenModules()
{
return Amazon.RegionEndpoint.EnumerableAllRegions
.Where(x => !IsSpetialRegion(x.SystemName))
View 01_Basic_TryExpressionTree.cs
void Main()
{
// GOAL: (object target) => (object)((T)target).PropertyName
// target => Convert(Convert(target, MyClass).MyProperty, Object)
Expression<Func<object, object>> expr = target => ((MyClass)target).MyProperty;
//expr.Dump();
// trarget => Convert(Convert(trarget, MyClass).MyProperty, Object)
var type = typeof(MyClass);
View RouteLoggingMiddleware.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
namespace LoggerSample
{
public class RouteLoggingMiddleware
{
private readonly RequestDelegate _next;
@guitarrapc
guitarrapc / Main.cs
Created Jan 15, 2020
Deserialize Pulumi Resource JSON
View Main.cs
void Main()
{
var json = File.ReadAllText(@"pulumi_20200115.json");
var pulumi = System.Text.Json.JsonSerializer.Deserialize<PulumiResource>(json);
var parents = pulumi.deployment.resources.Select(x => x.parent).Where(x => x != null).ToArray();
var keys = pulumi.deployment.resources.Select(x => x.urn).ToArray();
}
View DetectEol.cs
public static class DetectEndOfLine
{
public static EndOfLineStyle Detect(string pathToFile)
{
int bufl = 0;
var buf = ArrayPool<char>.Shared.Rent(8192);
try
{
return DetectCore(pathToFile, buf, bufl);
}
View TimeOutXunit.cs
[Fact(Timeout = 50)]
public async Task FactTimeout_TimeoutLessThanProcessingTime_ThrowTestTimeoutException()
{
Action act = () => Task.Delay(5000);
// Trigger the timeout by attempting something that will take too long
await act;
}
@guitarrapc
guitarrapc / Sample.runsettings
Last active Dec 13, 2019
dotnet test RunConfiguration
View Sample.runsettings
<RunConfiguration>
<MaxCpuCount>1</MaxCpuCount>
<ResultsDirectory>.\TestResults</ResultsDirectory>
<TargetPlatform>x86</TargetPlatform>
<TargetFrameworkVersion>Framework40</TargetFrameworkVersion>
<TestAdaptersPaths>%SystemDrive%\Temp\foo;%SystemDrive%\Temp\bar</TestAdaptersPaths>
<TestSessionTimeout>10000</TestSessionTimeout>
</RunConfiguration>
View install_redisinsight.sh
#!/bin/bash
curl -O https://downloads.redisinsight.redislabs.com/latest/redisinsight-linux64
chmod +x redisinsight-linux64
./redisinsight-linux64
@guitarrapc
guitarrapc / modify_draining.sh
Created Dec 11, 2019
Modify NLB Draining manually.
View modify_draining.sh
#!/bin/bash
name=your_lb_svc
draining=30
lb=$(kubectl get service $name -o jsonpath="{.status.loadBalancer.ingress[*].hostname}")
arn=$(aws elbv2 describe-load-balancers --query "LoadBalancers[?DNSName=='$lb'].[LoadBalancerArn]" | jq -r '.[][]')
aws elbv2 describe-target-groups --load-balancer-arn $arn | jq -r ".TargetGroups[].TargetGroupArn" | \
xargs -I {} aws elbv2 modify-target-group-attributes --target-group-arn "{}" --attributes Key=deregistration_delay.timeout_seconds,Value=$draining
@guitarrapc
guitarrapc / UnitTest1.cs
Created Nov 29, 2019
dotnet test / dotnet vstest and console output on success. https://github.com/xunit/xunit/issues/1141
View UnitTest1.cs
public class UnitTest1
{
public UnitTest1(ITestOutputHelper output)
{
var listener = new TestTraceListener(output);
Trace.Listeners.Add(listener);
_output = listener;
}
class TestTraceListener : TraceListener
You can’t perform that action at this time.