Skip to content

Instantly share code, notes, and snippets.

View mhagrelius's full-sized avatar

Matthew Hagrelius mhagrelius

  • Carvana
  • Scottsdale, AZ, USA
View GitHub Profile
@mhagrelius
mhagrelius / DeadLetterDrain.csproj
Created April 28, 2021 22:24
Azure Service Bus Dead Letter Queue Drain
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.1.2"/>
<PackageReference Include="CsvHelper" Version="27.0.2"/>
</ItemGroup>
</Project>
@mhagrelius
mhagrelius / steps.md
Created October 4, 2019 13:04
Steps to encrypt web.config

For Single Box

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -pef connectionStrings "C:\Folder\Project"

To Share Across Environments

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -pc "SiteRSAEncryptionKeys" -exp C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -pa "SiteRSAEncryptionKeys" "COMPUTER\UserName"

Setup ConfigProtectedData section of web.config

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -pef connectionStrings "C:\Folder\Project" -prov "SiteRSAEncryptionProvider"

@mhagrelius
mhagrelius / BitManipulation.cs
Created October 3, 2019 18:11
Useful bit manipulation functions
public static class BitManipulation
{
public static bool CheckBitSet(int num, int bit)
{
return ((num & (1 << bit)) != 0);
}
public static int SetBit(int num, int bit)
{
return num | (1 << bit);
@mhagrelius
mhagrelius / AuthHelpers.cs
Created October 2, 2019 20:57
Get Access Token from Azure AD for Integration Testing
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
namespace Api.Test
{
public static class AuthHelpers
{
@mhagrelius
mhagrelius / azure-pipelines.yaml
Created October 2, 2019 20:53
Azure DevOps Pipeline Example
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
name: Default
@mhagrelius
mhagrelius / IAsyncEnumerable.cs
Created October 2, 2019 19:17
IAsyncEnumerable ADO.NET Example
public static async IAsyncEnumerable<IEnumerable<object?>> GetResults(this SqlConnection connection, string query, [EnumeratorCancellation] CancellationToken token)
{
if (string.IsNullOrWhiteSpace(query))
{
throw new ArgumentException(nameof(query));
}
var wasClosed = connection.State != ConnectionState.Open;
try
{
if (wasClosed)
@mhagrelius
mhagrelius / Program.cs
Created September 26, 2019 02:09
Stop Sonos Wifi Across Network
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace SonosStopper
{
class Program
{
static async Task Main(string[] args)
@mhagrelius
mhagrelius / index.js
Created September 26, 2019 01:53
Basic Internet Troubleshooter
#! /usr/bin/env node
const colors = require("colors");
const ping = require("ping");
const util = require("util");
const readline = require("readline");
const speedTest = require("speedtest-net");
const addresses = {
"router": "192.168.1.1"
@mhagrelius
mhagrelius / auth.js
Created September 26, 2019 01:32
Azure Ad + Passport.js + Microsoft Graph groups
'use strict'
const axios = require('axios').default
const passport = require('passport')
const { BearerStrategy } = require('passport-azure-ad')
const queryString = require('query-string')
const options = {
identityMetadata: `https://login.microsoftonline.com/${
process.env.AZURE_TENANTID
@mhagrelius
mhagrelius / run-tests.sh
Created September 26, 2019 01:13
Script for collecting code coverage
#!/bin/bash
dotnet test ./Example.Test/Example.Test.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info /p:Exclude="[xunit*]*%2c[*]*.generated.cs%2c[Example.Test]*"