Skip to content

Instantly share code, notes, and snippets.

View xakpc's full-sized avatar

Pavel Osadchuk xakpc

View GitHub Profile
@xakpc
xakpc / Program.cs
Created September 25, 2023 10:17
Middleware to check header example
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.Configure<RouteHandlerOptions>(o => o.ThrowOnBadRequest = true);
var app = builder.Build();
// middleware to check content-type header
app.Use(async (context, next) =>
@xakpc
xakpc / HashnodeSitemapFunction.cs
Created September 19, 2023 22:39
Azure Function To Fix Hashnode Sitemap
using System;
using System.IO;
using System.Threading.Tasks;
using System.Web.Http;
using System.Xml.Serialization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
@xakpc
xakpc / emoji-favioc.html
Created September 14, 2023 08:14
Inline Emoji as a Favicon
<!--
* href="data:image/svg+xml,...":
Instead of linking to an external file, this code provides the image data directly inline using a data: URL.
image/svg+xml indicates that the data is an SVG image.
* The SVG (Scalable Vector Graphics) is an XML-based vector image format.
** viewBox=%220 0 100 100%22 - This SVG defines a simple image with a width and height of 100x100 units.
* The content of the SVG is a text representation of the clipboard emoji (📋).
@xakpc
xakpc / simple.cs
Last active August 31, 2022 21:38
Return JsonResult with settings from Azure Function V4
// check your functions version in .csproj
// check your function is out-of-process (assembly file)
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
// install package
Install-Package Microsoft.AspNetCore.Mvc.NewtonsoftJson
// it will give you generic JsonResult
/// <summary>
/// Creates a new <see cref="JsonResult"/> with the given <paramref name="value"/>.
@xakpc
xakpc / 1-simple.cs
Last active August 31, 2022 21:14
Setup Newtonsoft.Json in Azure Functions v4
// check your functions version in .csproj
// check your function is out-of-process (assembly file)
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
// install package
Install-Package Microsoft.AspNetCore.Mvc.NewtonsoftJson
// provide startup class
[assembly: FunctionsStartup(typeof(Xakpc.FeedbackBots.Startup))]
@xakpc
xakpc / Countdown.razor
Created June 5, 2022 18:30
a simple countdown timer with dotnet Blazor
<div class = "clock">
<h1>@Time</h1>
</div>
@xakpc
xakpc / create-bot.sh
Last active February 26, 2021 21:45
Code-samples for API.chat blogposts
curl -v -X PUT "https://bot.api.chat/v1/bots/botName/scenario"
-H "Content-Type: application/xml"
-H "Cache-Control: no-cache"
-H "Ocp-Apim-Subscription-Key: your-subscription-key"
--data-raw '
<bot>
<states>
<state name="Start">
<transition input="hello" next="Start">Hello from chatbot</transition>
<transition input="*" next="Start" morphology="msg">You send me {msg}</transition>
@xakpc
xakpc / CommandButton.razor
Created October 13, 2020 14:31
Blazor Essentials
@using System.Windows.Input
<button type="button" class="@($"btn {Class}")" @onclick="Callback" @attributes="InputAttributes">@ChildContent</button>
@code {
[Parameter]
public ICommand Command { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; }
@xakpc
xakpc / ContextComponentBase.cs
Created October 1, 2020 17:22
Blazor ContextComponentBase (for MVVM)
/// <summary>
/// ComponentBase with DataContext
/// </summary>
public class ContextComponentBase : ComponentBase
{
/// <summary>
///
/// </summary>
protected ViewModelBase DataContext { get; set; }
@xakpc
xakpc / Card.razor
Created September 30, 2020 23:45
Card template for Blazor Bootstrap
<div class="card @Class" @attributes="InputAttributes">
@if (Title != null)
{
<div class="card-header">
<h5 class="card-title">@Title</h5>
</div>
}
<div class="card-body">
@ChildContent
</div>