Skip to content

Instantly share code, notes, and snippets.

💭
I may be slow to respond as I'm super busy with bill paying client work!

James Randall JamesRandall

💭
I may be slow to respond as I'm super busy with bill paying client work!
Block or report user

Report or block JamesRandall

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@JamesRandall
JamesRandall / HttpEventListener.cs
Last active Mar 13, 2019
Http Tracing in .net
View HttpEventListener.cs
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Globalization;
namespace HttpTracing
{
public class HttpEventListener : EventListener
{
@JamesRandall
JamesRandall / BlobStorageMultipartStreamProvider.cs
Last active Mar 12, 2019
Azure Blob Container Web API Image Upload
View BlobStorageMultipartStreamProvider.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
@JamesRandall
JamesRandall / RedirectNewtonsoftJson.ps1
Last active Feb 8, 2019
Powershell binding redirection
View RedirectNewtonsoftJson.ps1
# Load your target version of the assembly
$newtonsoft = [System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll")
$onAssemblyResolveEventHandler = [System.ResolveEventHandler] {
param($sender, $e)
# You can make this condition more or less version specific as suits your requirements
if ($e.Name.StartsWith("Newtonsoft.Json")) {
return $newtonsoft
}
foreach($assembly in [System.AppDomain]::CurrentDomain.GetAssemblies()) {
if ($assembly.FullName -eq $e.Name) {
View FunctionAppConfiguration.cs
public class FunctionAppConfiguration : IFunctionAppConfiguration
{
public void Build(IFunctionHostBuilder builder)
{
builder
.Setup((serviceCollection, commandRegistry) =>
{
serviceCollection
.AddCosmosRepository(Environment.GetEnvironmentVariable("cosmosConnectionString", EnvironmentVariableTarget.Process));
// rest of registration
@JamesRandall
JamesRandall / BearerTokenValidator.cs
Created Jun 16, 2018
Sample ITokenValidator implementation for FunctionMonkey
View BearerTokenValidator.cs
public class BearerTokenValidator : ITokenValidator
{
private static readonly IConfigurationManager<OpenIdConnectConfiguration> ConfigurationManager;
static BearerTokenValidator()
{
string domain = Environment.GetEnvironmentVariable("domain");
string wellKnownEndpoint = $"https://{domain}/.well-known/openid-configuration";
var documentRetriever = new HttpDocumentRetriever { RequireHttps = wellKnownEndpoint.StartsWith("https://") };
@JamesRandall
JamesRandall / getUmbracoPropertyContent.sql
Created Mar 18, 2018
Gets the values for a property from an Umbraco database
View getUmbracoPropertyContent.sql
select cpd.* from cmsPropertyData cpd
inner join cmsPropertyType cpt
on cpt.id = cpd.propertytypeid
and cpt.Alias='%propname%'
@JamesRandall
JamesRandall / gitChangeStatsByDay.ps1
Last active Mar 13, 2018
Script that runs through the git commit log and gets the number of additions and deletions made by date. Run the script in the folder of a git repository. See sampleoutput.csv for, errr, sample output
View gitChangeStatsByDay.ps1
# Not the best written script in the world but it does a job.
Param(
[string]$path="stats.csv"
)
$commitHashes = git log --pretty=format:"%h"
$commitDates = git log --pretty=format:"%ad" --date=short
$deletions = @()
$additions = @()
$changesOverTime = @()
@JamesRandall
JamesRandall / RedBlackTree.cs
Last active Mar 4, 2018
Red-Black Tree Implementation in C#
View RedBlackTree.cs
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace OpinionatedCode.Collections
{
public sealed class RedBlackTree<TKey, TValue>
{
private readonly RedBlackTreeNode<TKey, TValue> _leaf = RedBlackTreeNode<TKey, TValue>.CreateLeaf();
View gist:87c31114ebde542f82cbb9c2fe2ae7c6
/*
Nuget packages included:
- AzureFromTheTrenches.Commanding 6.1.0
- AzureFromTheTrenches.Commanding.MicrosoftDependencyInjection 6.1.0
- Microsoft.Extensions.DependencyInjection 2.0.0
*/
using System;
using System.Threading.Tasks;
using AzureFromTheTrenches.Commanding;
@JamesRandall
JamesRandall / RedirectRootToSwagger.cs
Created Aug 13, 2016
Redirect the root path of an Owin hosted application to the swagger end point
View RedirectRootToSwagger.cs
using System.Net;
using Owin;
namespace MyApplication.Api.Extensions
{
// ReSharper disable once InconsistentNaming
public static class IAppBuilderExtensions
{
public static IAppBuilder RedirectRootToSwagger(this IAppBuilder app)
{
You can’t perform that action at this time.