Skip to content

Instantly share code, notes, and snippets.

@madhub
Last active October 10, 2023 03:18
Show Gist options
  • Save madhub/6c5ab97064c235a41b09e803270536a3 to your computer and use it in GitHub Desktop.
Save madhub/6c5ab97064c235a41b09e803270536a3 to your computer and use it in GitHub Desktop.

Using C# Channales

API version in ASP.NET Core 7

Using Problem Details in Asp.net Core

https://buildkite.com/blog/goodbye-integers-hello-uuids UUIDv7 image

Kubernetes Debug Containers https://github.com/zinclabs/debug-container

Here is how to use AWS Text Extract to get data as keyvalue from the form Example usecase is to extrac key/value from W2 Tax form URL Textract documentation.

@inject IAmazonTextract TextractClient;
FileStream fileStream = new FileStream(uploadedFilePath, FileMode.Open, FileAccess.Read);

MemoryStream memoryStream = new MemoryStream();


await fileStream.CopyToAsync(memoryStream);

await fileStream.FlushAsync();


var analyzeDocumentRequest = new AnalyzeDocumentRequest()

{

    Document = new Document { Bytes = memoryStream },

    FeatureTypes = new List<string> { "FORMS" },

};


var analyzeDocumentResponse = await TextractClient.AnalyzeDocumentAsync(analyzeDocumentRequest);

keyValuePairs = analyzeDocumentResponse.GetKeyValuePairs();

Handling CancelKeyPress using a CancellationToken https://www.meziantou.net/detecting-console-closing-in-dotnet.htm

const int WaitIndefinitely = -1;
using var cts = new CancellationTokenSource();
Console.CancelKeyPress += (sender, e) =>
{
    // We'll stop the process manually by using the CancellationToken
    e.Cancel = true;

    // Change the state of the CancellationToken to "Canceled"
    // - Set the IsCancellationRequested property to true
    // - Call the registered callbacks
    cts.Cancel();
};


try
{
    // code using the cancellation token
    Console.WriteLine("Waiting");
    await Task.Delay(WaitIndefinitely, cts.Token);
}
catch (OperationCanceledException)
{
    Console.WriteLine("Operation canceled");
}

Console.WriteLine("Closing application...");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment