Skip to content

Instantly share code, notes, and snippets.

Avatar

Marnix van Valen alanta

View GitHub Profile
@alanta
alanta / azure-waf-rule-with-overrides.json
Created May 2, 2021
Disable specific built-in firewall rules that are causing excessive blocking on an Azure Application Gateway.
View azure-waf-rule-with-overrides.json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {
"publicSitePolicy": "my-wafpolicy-for-public-sites",
"htmlOwaspRuleOverrides": [
{
"ruleGroupName": "REQUEST-932-APPLICATION-ATTACK-RCE",
"rules": [
@alanta
alanta / SingletonEternalFunctionWithWatchdogTimer.cs
Last active Nov 27, 2020
Singleton eternal function with watchdog timer
View SingletonEternalFunctionWithWatchdogTimer.cs
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace DurableFunctionsPatterns
{
public class EternalFunctionWithWatchdogTimer
@alanta
alanta / AlwaysOn.cs
Created May 14, 2020
Azure Web Apps with Always On enabled poll your web app every 5 minutes. If there's nothing listening on that url this results in a 404 response which shows up as an error in monitoring.
View AlwaysOn.cs
public static class AlwaysOn
{
/// <summary>
/// Prevent 404 on the application root URL. Azure Web Apps with Always On enabled invoke the root of the application every 5 minutes
/// to keep your web app awake. If you run an API-only app you likely have nothing listening to /, which results in a 404 response
/// that shows up in monitoring. This endpoint returns 200 with content Ok only for the always on check.
/// </summary>
/// <param name="builder">The application builder.</param>
/// <returns>The application builder.</returns>
public static IApplicationBuilder UseAlwaysOn(this IApplicationBuilder builder)
@alanta
alanta / All_functions_can_be_instantiated.cs
Last active Apr 10, 2020
Generic integration test to verify all functions can be instantiated by the function host. This helps prevent problems when using the .NET Core default dependency injection container with Azure Functions.
View All_functions_can_be_instantiated.cs
public class When_the_function_host_is_configured
{
[Theory]
[MemberData(nameof(Functions))]
public void It_should_be_able_to_instantiate_all_functions(Type functionType)
{
// Arrange
var startup = new MyFunctions.Startup();
var host = new HostBuilder()
.ConfigureWebJobs(cfg =>
@alanta
alanta / When_the_application_is_configured.cs
Created Mar 27, 2020
Ensure your ASP.NET Core application can create all it's controllers
View When_the_application_is_configured.cs
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
View grant-keyvault-access.ps1
param ([Parameter(Mandatory)]$keyvaultname)
$userid = az ad signed-in-user show --query objectId
if($LASTEXITCODE){
Write-Information "Please login using 'az login' and make sure you select the correct subscription with 'az account'"
}
az keyvault set-policy -n $keyvaultname --secret-permissions backup delete get list purge recover restore set --object-id $userid
@alanta
alanta / Anonymize non-admin users.sql
Created Dec 14, 2018
These SQL scripts delete ALL Personally Identifiable Information from a Kentico database. Use this to clean up a database before pulling it from production to test or dev and still be GDPR-safe.
View Anonymize non-admin users.sql
UPDATE [dbo].[CMS_User]
SET
UserName=CONCAT('U',UserID),
FirstName= CONCAT('U',UserID),
MiddleName=NULL,
LastName='Anoniem',
FullName= CONCAT('U',UserID,' Anoniem'),
Email=CONCAT('U',UserID,'@localhost'),
UserPassword=CONVERT(NVARCHAR(32),HashBytes('SHA1', 'Super secret password'),2),
@alanta
alanta / Round.cs
Created May 24, 2017
Version 2 of benchmark tests for fast rounding code
View Round.cs
using System;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Runtime.InteropServices;
namespace ClassLibrary2
{
public class Rounding
{
@alanta
alanta / Round.cs
Created May 21, 2017
benchmark tests for rounding floats in C#
View Round.cs
using System;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ClassLibrary2
{
public class Rounding
{
private const int N = 100000;
@alanta
alanta / addselftosqlsysadmin.cmd
Last active Sep 5, 2015 — forked from wadewegner/addselftosqlsysadmin.cmd
Script to add the current user to the sysadmin role in SQL Server
View addselftosqlsysadmin.cmd
@echo off
rem
rem ****************************************************************************
rem
rem Copyright (c) Microsoft Corporation. All rights reserved.
rem This code is licensed under the Microsoft Public License.
rem THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
rem ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
rem IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
rem PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.