Skip to content

Instantly share code, notes, and snippets.

View alanta's full-sized avatar

Marnix van Valen alanta

View GitHub Profile
@alanta
alanta / addselftosqlsysadmin.cmd
Last active September 5, 2015 12:11 — forked from wadewegner/addselftosqlsysadmin.cmd
Script to add the current user to the sysadmin role in SQL Server
@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.
@alanta
alanta / Round.cs
Created May 21, 2017 21:23
benchmark tests for rounding floats in C#
using System;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ClassLibrary2
{
public class Rounding
{
private const int N = 100000;
@alanta
alanta / Round.cs
Created May 24, 2017 20:44
Version 2 of benchmark tests for fast rounding code
using System;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Runtime.InteropServices;
namespace ClassLibrary2
{
public class Rounding
{
@alanta
alanta / Anonymize non-admin users.sql
Created December 14, 2018 05:37
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.
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),
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 / When_the_application_is_configured.cs
Created March 27, 2020 16:13
Ensure your ASP.NET Core application can create all it's controllers
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;
@alanta
alanta / All_functions_can_be_instantiated.cs
Last active April 10, 2020 06:35
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.
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 / CmdHttpModule.cs
Created August 23, 2011 08:08
Fix Sitefinity url handling and rewriting
using System;
using System.Configuration;
using System.Web;
using Telerik.Cms.Web;
namespace Alanta.Sitefinity
{
public class CmsHttpModule : IHttpModule
{
private Telerik.Cms.Web.CmsHttpModule _cmsHttpModule;
@alanta
alanta / SingletonEternalFunctionWithWatchdogTimer.cs
Last active November 27, 2020 13:52
Singleton eternal function with watchdog timer
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 / azure-waf-rule-with-overrides.json
Created May 2, 2021 21:00
Disable specific built-in firewall rules that are causing excessive blocking on an Azure Application Gateway.
{
"$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": [