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
View FizzBuzz.ps1
#50 {Fizz}[0] = Fizz
1..100|%{($t=""+{Fizz}[$_%3]+{Buzz}[$_%5])?$t :$_}
#51 "Fizz"*$true = Fizz
1..100|%{($t='Fizz'*!($_%3)+'Buzz'*!($_%5))?$t :$_}
#54
1..100|%{$t=$_%3?"":"Fizz";$_%5?$t ?$t :$_ :$t+"Buzz"}
#55
View CSaharp9_TargetTypedNew.cs
using System;
using System.Collections.Generic;
public class TargetTypedNewClass1
{
// no right side type inference (C# 8)
static readonly Dictionary<string, string> cache1 = new Dictionary<string, string>();
// target typed new. right side type inferenece (C# 9.0)
static readonly Dictionary<string, string> cache2 = new();
@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>
You can’t perform that action at this time.