Skip to content

Instantly share code, notes, and snippets.

View guitarrapc's full-sized avatar
:octocat:

Ikiru Yoshizaki guitarrapc

:octocat:
View GitHub Profile
@guitarrapc
guitarrapc / Program.cs
Last active January 23, 2025 12:32
Convert DefaultAzureCredential to AzureCredentials.
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
// DefaultAzureCredentialで認証をとって Token を取得する
var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions { /* VSを除外したりとオプション指定 */ });
var defaultToken = await credential.GetTokenAsync(new TokenRequestContext(new[] { "https://management.azure.com/.default" }));
@guitarrapc
guitarrapc / DefaultAzureCredential.cs
Created July 5, 2022 16:01
Create DefaultAzureCredential for Azure SDK for .NET
using System;
using System.Threading.Tasks;
using Azure.Identity;
// ServicePrincipal なら 環境変数に仕込んで認証できる
// Environment.SetEnvironmentVariable("AZURE_CLIENT_ID", "<reducted>", EnvironmentVariableTarget.Process);
// Environment.SetEnvironmentVariable("AZURE_CLIENT_SECRET", "<reducted>", EnvironmentVariableTarget.Process);
// Environment.SetEnvironmentVariable("AZURE_TENANT_ID", "<reducted>", EnvironmentVariableTarget.Process);
// インスタンス生成はこれだけ
@guitarrapc
guitarrapc / AzureCredntials.cs
Last active July 5, 2022 16:10
Create AzureCredntials for Azure SDK for .NET
using Microsoft.Azure.Management.PostgreSQL.FlexibleServers;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
using System.Threading.Tasks;
// SdkContext から生成する場合
// var cred = SdkContext.AzureCredentialsFactory.FromMSI(new MSILoginInformation(MSIResourceType.AppService), AzureEnvironment.AzureGlobalCloud);
// var cred = SdkContext.AzureCredentialsFactory.FromServicePrincipal("<clientId>", "<clientSecret>", "<tenantId>", AzureEnvironment.AzureGlobalCloud);
// new AzureCredentials でインスタンスを渡して生成する場合
@guitarrapc
guitarrapc / Pulumi_ResourcePropertyChanged.md
Last active June 21, 2022 05:14
Pulumi のパッケージ更新をしたらプロパティ名が変わっており craete-replacement が生じしてしまった時の対処方法

Pulumi リソースのプロパティが変わってしまい create-replacement が発生する場合の対処方法

tl;dr;

  • リソースのプロパティ名変更に対応するには、一度該当 URN を Stateから削除して、インポートしなおす。
  • 残念ながら、リソースの必須プロパティ名の変更で生じる reate-replacement に対処できる Custom Resource Options は存在しない。

see: Allow aliasing when a property which requires replacement changes name · Issue #9115 · pulumi/pulumi pulumi/pulumi#9115

問題の概要

@guitarrapc
guitarrapc / Allow-WSL2UuntuFirewall.ps1
Created June 12, 2022 15:14
Allow WSL2 Ubuntu 22.04 to access Host Windows Docker Desktop (Windows 11 21H2)
# set this on Windows TaskScheduler with `At Logon, Run with highest priviledge, Delay task for 1min`
wsl.exe -d Ubuntu-22.04 --exec cat /etc/resolv.conf
Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)" -Name Public
void Main()
{
// 符号なし (unsigned) の 0xFF = 255
byte u = 0xFF;
// 符号付き (signed) の 0xFF = -1
sbyte s = (sbyte)u;
// 符号なしを右シフトすると、左端には 0 が入る。
// 11111111 FF
@guitarrapc
guitarrapc / ExponentialBackoff.cs
Last active June 1, 2022 10:40
ExponentialBackoff Implemantation via C#.
public class ExponentialBackoff
{
private readonly int _delayMilliseconds;
private readonly int _maxDelayMilliseconds;
public int Retries => _retries;
private int _retries;
private int _pow;
public ExponentialBackoff(int delayMilliseconds, int maxDelayMilliseconds)
{
name: README embed-code
on:
workflow_dispatch:
pull_request:
branches: ["main"]
jobs:
embed-code:
runs-on: ubuntu-latest
This is a *markdown* document with a code block:

```ts
// src/example.ts

export function helloWorld(name: string): string {
  return `Hello ${name}!, how are you today?`;
}
This is a *markdown* document with a code block:

```ts
// src/example.ts