Skip to content

Instantly share code, notes, and snippets.

View xiaomi7732's full-sized avatar
๐Ÿ˜ƒ
Active

Saar Shen xiaomi7732

๐Ÿ˜ƒ
Active
View GitHub Profile
@xiaomi7732
xiaomi7732 / GuidObsession.cs
Created January 4, 2022 18:41
Learn primitive obsession - attempt 1
InsightsInstrumentationKey iKey = "12345";
PrintResult(iKey);
iKey = "6e12e0b1-0cbd-4fe9-9b5d-2d8a46e672fe";
PrintResult(iKey);
iKey = Guid.NewGuid();
PrintResult(iKey);
void PrintResult(InsightsInstrumentationKey iKey)
@xiaomi7732
xiaomi7732 / AsyncVoidIsEvil.cs
Created January 17, 2022 00:21
Why async void is evil
async void AsyncJob()
{
await Task.Delay(100);
throw new InvalidOperationException("Hello exception!");
// Console.WriteLine("Job is done!");
}
try
{
// Notice: the exception thrown by AsyncJob won't be
@xiaomi7732
xiaomi7732 / Xamarin.Android.PlatformEncryptionKeyHelper.cs
Created January 19, 2022 05:33 — forked from MSiccDev/Xamarin.Android.PlatformEncryptionKeyHelper.cs
Helper class to securely create encryption keys without the need of user interaction on Android. There are way to much samples that use some hardcoded values which could be compromised. The keys of this class are only available for usage within the app that created them. Plus, if the app gets uninstalled, the keys get deleted.
using Android.Content;
using Android.OS;
using Android.Security;
using Android.Security.Keystore;
using Java.Math;
using Java.Security;
using Javax.Security.Auth.X500;
using Calendar = Android.Icu.Util.Calendar;
using CalendarField = Android.Icu.Util.CalendarField;
@xiaomi7732
xiaomi7732 / HiddenDisposables.md
Created January 21, 2022 06:21
Hidden Disposables - Refresh
@xiaomi7732
xiaomi7732 / UploadBlobWithOptionsAllowOverwrite.md
Created January 28, 2022 01:44
Upload Blob with BlobUploadOptions + Allow overwrite

Overwrite + BlobOptions in 1 shot

The Azure Storage SDK doens't provide an overload to have both parameters for overwrting and a BlobUploadOptions. But that is a common scenario. By reading the implementations, it looks like it is easy to do:

using (Stream contentStream = File.OpenRead(@"C:\tmp\Test.txt"))
{
    BlobUploadOptions overwriteWithTags = new BlobUploadOptions
    {
@xiaomi7732
xiaomi7732 / CopyFilesToBuildOutputInProjectFile.md
Last active February 4, 2022 04:13
Copy files to build output

This is a cheetsheet to copy files to output directory in a MSBuild project file.

For example, this will copy settings.json to output directory when the one in current folder is newer.

<Project Sdk="Microsoft.NET.Sdk">
  ...
  <ItemGroup>
    <!-- Build action is `None`, and the option for copy to output directory could be `Always` or `PreserveNewest` -->
    <None Include="./settings.json" CopyToOutputDirectory="PreserveNewest" />
 
@xiaomi7732
xiaomi7732 / HowToEnableAzureFunctionScaleControllerLogs.md
Created February 10, 2022 22:22
How to enable Azure Function Scale Controller Logs

How to enable Azure Function Scale Controller Logs

Enable logging for azure funciton scale controller is useful for troubleshooting auto scale issues.

Set variable:

SCALE_CONTROLLER_LOGGING_ENABLED = <DESTINATION>:<VERBOSITY>
@xiaomi7732
xiaomi7732 / AzureFunctionScaleControllerDebugging.md
Created February 16, 2022 00:42
Why my Azure Function didn't auto-scale & how did I find it out

Why my Azure Function didn't auto-scale & how did I find it out

This is a retrospective. I had an Azure Function, connected to a ServieBus Topic for message processing. It functions, messages triggered the function, function processed the message, all good, except it didn't scale no matter how many message was stacked up in the topic.

To debug it, I built a lab with mimimum components. To share some context, this is how the trigger attribute looks like on the function:

[Function("OnGetMessage")]
public void Run([ServiceBusTrigger("message", "message-sub", Connection = "LabServiceBus")] string mySbMsg)
@xiaomi7732
xiaomi7732 / EditorConfigCheatSheetForUnderScoreReadOnlyField.md
Last active February 18, 2022 01:20
EditorConfigCheatSheetForUnderScoreReadOnlyField

This is a cheatsheet for generating underscore for readonly field by editorconfig:

[*.{cs,vb}]
dotnet_naming_rule.private_members_with_underscore.symbols  = private_fields
dotnet_naming_rule.private_members_with_underscore.style    = prefix_underscore
dotnet_naming_rule.private_members_with_underscore.severity = suggestion

dotnet_naming_symbols.private_fields.applicable_kinds           = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

Troubleshooting guidance for DI

This is supposed to be a quick checklist / cheatsheet to help debug DI failures.

Common errors checklist

These are easy issues that happened to me.

Having a quick check, sometimes, this is the most efficent way to catch a bug: