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 / InstallChromeDriver.Old.ps1
Last active September 4, 2023 03:42
Install ChromeDriver using PowerShell on Windows/Linux/MacOS, for more information read this blog post: https://swimburger.net/blog/powershell/download-the-right-chromedriver-on-windows-linux-macos-using-powershell
[CmdletBinding()]
param (
[Parameter(Mandatory = $True)]
[string]
$ChromeDriverOutputPath,
[Parameter(Mandatory = $false)]
[string]
$ChromeVersion,
[Parameter(Mandatory = $false)]
[Switch]
Param(
[Parameter(Mandatory = $true)]
[string] $ResourceGroupName,
[Parameter(Mandatory = $true)]
[string] $AppServiceName,
[Parameter(Mandatory = $true)]
[string] $SubscriptionId,
[Parameter(Mandatory = $true)]
[string] $RulePriority
)
@Swimburger
Swimburger / CrawlSite.ps1
Last active June 27, 2023 22:24
Crawl your website links and images to find broken links/images using PowerShell
Param(
[Parameter(Mandatory=$true)]
[string] $Url,
[Parameter(Mandatory=$true)]
[int] $MaxPages,
[bool] $IncludeImages = $true,
[bool] $StayOnDomain = $true,
[bool] $IgnoreFragments = $true)
Add-Type -AssemblyName System.Web
@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 / IISRewriteRules.config
Created October 8, 2018 00:02
Add trailing slash to URL redirects IIS web.config
<rule name="Add trailing slash" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>
@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: