Skip to content

Instantly share code, notes, and snippets.

View xiaomi7732's full-sized avatar

Saar Shen xiaomi7732

View GitHub Profile
@xiaomi7732
xiaomi7732 / ApiVersionAttribute.cs
Created July 31, 2023 21:04 — forked from commonsensesoftware/ApiVersionAttribute.cs
Implement Custom API Version Format
public sealed class ApiVersionAttribute : Asp.Versioning.ApiVersionAttribute
{
public ApiVersionAttribute( string version )
: base( CustomApiVersionParser.Default, version ) { }
public ApiVersionAttribute( string token1, string token2, string? token3 = default )
: base( new CustomApiVersion( token1, token2, token3 ) ) { }
}
@xiaomi7732
xiaomi7732 / LinkFile.md
Created July 26, 2023 23:54
Link a file in csproj for compiling

Needs to do this from time to time.

  <ItemGroup>
    <Compile Include="..\ServiceProfiler2\src\ServiceProfiler.Analysis.DataModels\Insights\InsightRecord.cs" Link="InsightRecord.cs" />
  </ItemGroup>
@xiaomi7732
xiaomi7732 / DockerizeASPNetCore.md
Last active June 8, 2023 00:31
Run an ASP.NET Web docker container

Command:

docker run -it -p localport:containerport --rm <containerTag>

Example:

docker run -it -p 8080:80 --rm dotnet-diag-webapi-example:latest
@xiaomi7732
xiaomi7732 / BashIntoContainers.md
Created May 19, 2023 04:58
Bash into containers

Bash into containers

Docker container

docker exec -it <container name> /bin/bash

Kubernetes

@xiaomi7732
xiaomi7732 / MyGitCheatSheet.md
Last active May 18, 2023 17:26
My Git Cheatsheet

My Git Cheatsheet

Commands that I use from time to time, but not that frequent.

Push a specific tag to remote

git push origin tag_name
@xiaomi7732
xiaomi7732 / MatrixAndIfCondition.md
Created March 9, 2023 21:19
Matrix + if condition in GitHub action

Shorthand:

if: matrix.project == 'src/OPI.WebAPI'

Full example:

jobs:
@xiaomi7732
xiaomi7732 / InitGitSubmodule.md
Created March 8, 2023 21:46
Bring down files in submodules for the first time
git submodule update --init
@xiaomi7732
xiaomi7732 / Directory.Build.props.example.md
Created February 28, 2023 21:54
Directory.Build.props example
  1. Filename is case sensitive on linux.
  2. Pay attention to the Import for casecading.
<Project>
    <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
    <PropertyGroup>
        <LangVersion>11.0</LangVersion>
    </PropertyGroup>
@xiaomi7732
xiaomi7732 / DiskSpaceForMounted.md
Last active February 23, 2023 22:30
Get proper disk space for mounted volume

This siutation is encountered in Azure Function where we want to have telemetries for available space for temp as well as home. It is a general issue of getting available space for mounted folder.

See the result, notice the difference between using different ways to get free space for the same folder? Why? image

Assuming temp folder location: c:\users\abc\temp, disk c has 1G free, and temp is mounted from another volume that has 5G.

This gets the free disk space for the driver, not for the mounted folder - 1G:

@xiaomi7732
xiaomi7732 / BindOptionsForLibraryDesign.md
Created February 8, 2023 18:10
Clearly bind options for library code
  • NuGet packages:

    <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.2" />
  • Code