Skip to content

Instantly share code, notes, and snippets.

View xakpc's full-sized avatar

Pavel Osadchuk xakpc

View GitHub Profile
#region Process auto layout
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
var btnPadding = 61;
var tblPadding = 100;
var btnWidth = 100;
var btnHeight = 50;
// constraints
@xakpc
xakpc / Global.asax.cs
Last active August 1, 2017 22:04
ASP.NET WebAPI requests logger by MessageHandler
using System.Diagnostics;
using System.Web;
using Hangfire;
using Hangfire.SimpleInjector;
using GlobalConfiguration = System.Web.Http.GlobalConfiguration;
namespace NameSpace
{
public class WebApiApplication : HttpApplication
{
@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>
@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 / 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 / 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 / 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 / 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 / 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) =>