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 / 1-setup.md
Created September 25, 2019 15:16 — forked from troyfontaine/1-setup.md
Signing your Git Commits using GPG on MacOS Sierra/High Sierra

Methods of Signing with GPG

There are now two ways to approach this:

  1. Using gpg and generating keys
  2. Using Kryptonite by krypt.co

This Gist explains how to do this using gpg in a step-by-step fashion. Kryptonite is actually wickedly easy to use-but you will still need to follow the instructions

For using a GUI-based GIT tool such as Tower or Github Desktop, follow the steps here for signing with either GPG or Krypt.co.

@mhagrelius
mhagrelius / RoleClaimsTransformation.cs
Last active September 26, 2019 00:55
Workaround for Azure AD groups and Asp.Net Core Roles
namespace Example
{
public class RoleClaimsTransformation : IClaimsTransformation
{
public Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
{
var identity = principal.Identities?.FirstOrDefault();
if (identity == null)
{
return null;
@mhagrelius
mhagrelius / example.cs
Last active September 25, 2019 18:41
Retrieve Groups From Microsoft Graph
/*
Uses Flurl.Http instead of default http client
Your app registration will need the appropriate permissions for microsoft graph
*** Additional exception handling needed if in a production scenario ***
*/
public static class Program
{
public async Task Main()
@mhagrelius
mhagrelius / code-check.sh
Created September 26, 2019 01:06
Test for adherence to clean architecture guidelines
#!/bin/bash
RESULT=$(grep -r -i --include \*.cs --include \*.cshtml --exclude Startup.cs --exclude /bin/\* --exclude /obj/\* --exclude /Configuration/\*.cs "Infrastructure.Namespace.Here" FolderNameHere)
if [ -z "$RESULT" ]
then
echo $RESULT
exit 1
fi
echo "No issues found."
exit 0
@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]*"
@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 / 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 / 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 / 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 / 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