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 / 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 / AllowMarkdownCorsModule.cs
Last active Apr 9, 2016
Enable serving of static Markdown content to JavaScript running on any domain
View AllowMarkdownCorsModule.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MyWebsite.Helpers
{
public class AllowMarkdownCorsModule : IHttpModule
{
public void Init(HttpApplication context)
@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 / 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) {
@JamesRandall
JamesRandall / todo.jsx
Last active Aug 2, 2016 — forked from caike/todo.jsx
Simple Todo app demo using React + ES6
View todo.jsx
var allItems = []
allItems.push("Buy ingredients for Crock Pot");
allItems.push("Pick up chair at IKEA");
allItems.push("Go see mom");
class TodoList extends React.Component {
constructor(props){
super(props);
}
getInitialState() {
@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)
{
@JamesRandall
JamesRandall / routeProfileRenderer.js
Last active Feb 20, 2017
3d GPS Route Profile Rendering
View routeProfileRenderer.js
// When given a set of GPS points and a container DOM element the code below will render a 3d profile of your GPS route.
// It requires three.js and that libraries associated Orbit Controls to run.
// The gpsPoints parameter should be an array with the following structure:
// [{latitude:0.323234,longitude:56.23244,altitude:1.8},...]
// To use in most browers compile with Babel as it uses a smattering of ES2015
export default function attachRenderer(container, gpsPoints) {
const THREE = window.THREE
// haversine formula calcuates the distance in km between two points of lon,lat
function haversineDistanceKm(lon1,lat1,lon2,lat2) {
function toRad(deg) {
@JamesRandall
JamesRandall / MapAppServiceDomain.cs
Last active Mar 25, 2017
Demonstrates how to map a domain name to an Azure website programmatically
View MapAppServiceDomain.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Newtonsoft.Json.Linq;
static class DomainMapper
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 / 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();
You can’t perform that action at this time.