Skip to content

Instantly share code, notes, and snippets.

View Swimburger's full-sized avatar
🍔
Creating full snack content

Niels Swimberghe Swimburger

🍔
Creating full snack content
View GitHub Profile
@Swimburger
Swimburger / events.md
Last active March 16, 2024 17:15
3 options of event implementation for transcriber class

After some recent discussions about the C# events their drawbacks, specifically with async callbacks, I prototyped a couple of alternative event APIs for a Speech-To-Text library that I'm working on.

Please let me know which one you prefer, or better alternatives. 🙇

Option 1

For each event, have an event object to which you can subscribe and unsubscribe.

@Swimburger
Swimburger / Program.cs
Created April 28, 2023 21:22
Ad-hoc CRON jobs from a console application with Hangfire
using Hangfire;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHangfire(configuration => configuration
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseInMemoryStorage());
builder.Services.AddHangfireServer();
@Swimburger
Swimburger / ChangeEmptyStringToNull.cs
Created January 31, 2023 01:19
Replace empty strings with `null` recursively in .NET configuration sections
private static void ChangeEmptyStringToNull(IConfigurationSection configSection)
{
if (configSection == null) return;
if (configSection.Value == "") configSection.Value = null;
foreach (var childConfigSection in configSection.GetChildren())
{
ChangeEmptyStringToNull(childConfigSection);
}
}
@Swimburger
Swimburger / SendAndWaitUntilDelivered.json
Created December 17, 2022 22:15
Send messages but wait for delivery in Twilio Studio
{
"description": "Send Message and Wait until Delivered",
"states": [
{
"name": "Trigger",
"type": "trigger",
"transitions": [
{
"event": "incomingMessage"
},
@Swimburger
Swimburger / MvcTwimlExceptionHandling.cs
Last active December 14, 2022 23:33
Two different ways of doing catch-all exception handling, one for MVC only using an exception filter, one using exception handler middleware
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Twilio.AspNet.Core;
using Twilio.TwiML;
namespace TwimlErrorMessageAttribute.Controllers;
[Route("twilio")]
public class TwilioController : Controller
{
@Swimburger
Swimburger / README.md
Created November 18, 2022 17:08
Fixing breaking changes in the TwiMLResult class for Twilio.AspNet v7 release

Fixing breaking changes in the TwiMLResult class for Twilio.AspNet v7 release

The v7 release removed the string and XDocument overload for the TwiMLResult constructor. One solution to this is to stop using string and XDocument and replace the code using the MessagingResponse and VoiceResponse classes, so you can keep using TwiMLResult. However, if you want to keep using string and XDocument, I'll share some before and after code for string and XDocument for both ASP.NET Core MVC and ASP.NET MVC on .NET Framework.

ASP.NET Core MVC

Before v7 using string:

@Swimburger
Swimburger / .runsettings
Created August 31, 2022 21:13
Playwright runsettings for NUnit with SlowMo
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<Playwright>
<BrowserName>chromium</BrowserName>
<ExpectTimeout>5000</ExpectTimeout>
<LaunchOptions>
<Headless>false</Headless>
<Channel>msedge</Channel>
<SlowMo>200</SlowMo>
</LaunchOptions>
@Swimburger
Swimburger / DeDuplicateBitwarden.ps1
Created August 7, 2022 20:49
Scans for duplicates and removes them using the Bitwarden CLI
$Items = bw list items | ConvertFrom-Json
Function Compare-Values($Name, $Item1, $Item2) {
if ($Item1 -eq $Item2) {
Write-Host "$($Name): $Item1 =="
return $true
}
else {
Write-Host "⚠️ $($Name): $Item1 <> $Item2";
return $false
@Swimburger
Swimburger / Program.cs
Created March 16, 2022 21:35
ASP.NET Minimal API sample for Twilio webhooks
using Microsoft.AspNetCore.Mvc;
using Twilio.AspNet.Core.MinimalApi;
using Twilio.TwiML;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.MapGet("/sms", ([FromQuery] string from, [FromQuery] string body) =>
@Swimburger
Swimburger / SamplePage.razor
Created November 18, 2021 20:06
PageTitle component with hardcoded Suffix
<SuffixedPageTitle>Home Page</SuffixedPageTitle>