Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Ikiru Yoshizaki guitarrapc

:octocat:
View GitHub Profile
@guitarrapc
guitarrapc / Class1.cs
Last active Jul 28, 2020
null conditional operator ?. for struct
View Class1.cs
using System;
namespace ClassLibrary1
{
public class Class1
{
private static void Main(string[] args)
{
// enabled nullable reference type
A? a = new A(null);
@guitarrapc
guitarrapc / Main.cs
Last active Jul 14, 2020
Calculate Percentile
View Main.cs
void Main()
{
var data = new double[] { 2, 4, 6, 8, 13, 16, 22, 35, 40, 42, 48 };
var percs = new[] { 0.5, 0.66, 0.75, 0.80, 0.90, 0.95, 0.98, 0.99, 1.00 };
percs.Select(x =>
{
var percent = (int)(x * 100);
var percentile = MathUtil.Percentile(data, x);
var percentileInterpolation = MathUtil.PercentileInterpolation(data, x);
return new Result(percent, percentile, percentileInterpolation);
View list.ps1
using namespace System.Collections.Generic
function _f {
$l = New-Object "List[string]"
$l.Add("abc")
return $l
}
$list = _f
$list
# output: abc
@guitarrapc
guitarrapc / download_terraform-provider-sops.sh
Created Jun 25, 2020
Download terraform provider sops binary to terraform.d/plugin directory https://github.com/carlpett/terraform-provider-sops
View download_terraform-provider-sops.sh
#!/bin/bash -eux
curl -Ls https://github.com/carlpett/terraform-provider-sops/releases/download/v0.5.1/terraform-provider-sops_0.5.1_linux_amd64.zip -o terraform-provider-sops_linux.zip && \
mkdir -p terraform.d/plugins/linux_amd64/ && \
unzip -o ./terraform-provider-sops_linux.zip -d terraform.d/plugins/linux_amd64/ && \
rm -f terraform-provider-sops_linux.zip && \
git update-index --add --chmod=+x ./terraform.d/plugins/linux_amd64/terraform-provider-sops_v0.5.1
curl -Ls https://github.com/carlpett/terraform-provider-sops/releases/download/v0.5.1/terraform-provider-sops_0.5.1_windows_amd64.zip -o terraform-provider-sops_windows.zip && \
mkdir -p terraform.d/plugins/windows_amd64/ && \
unzip -o ./terraform-provider-sops_windows.zip -d terraform.d/plugins/windows_amd64/ && \
@guitarrapc
guitarrapc / vscode-extensions.txt
Last active Jun 7, 2020
list of my exnteions
View vscode-extensions.txt
$ code --list-extensions
EditorConfig.EditorConfig
hashicorp.terraform
me-dutour-mathieu.vscode-github-actions
ms-azuretools.vscode-docker
ms-kubernetes-tools.vscode-kubernetes-tools
ms-vscode-remote.remote-wsl
redhat.vscode-yaml
sohamkamani.code-eol
View FizzBuzz.ps1
#42 can't be treat `r as CR on codegolf
1..100|%{"$_`r"+{Fizz}[$_%3]+{Buzz}[$_%5]}
#45
1..100|%{@('Fizz')[$_%3]+@('Buzz')[$_%5]??$_}
#46 can't be treat `r as CR on codegolf
1..100|%{"$_`r"+'Fizz'*!($_%3)+'Buzz'*!($_%5)}
#48 can't be treat `r as CR on codegolf
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);
You can’t perform that action at this time.