Skip to content

Instantly share code, notes, and snippets.

View rmacfie's full-sized avatar
😎

Robert Macfie rmacfie

😎
  • Stockholm, Sweden
View GitHub Profile
@rmacfie
rmacfie / C# hash generator
Created February 15, 2011 19:21
Generate Md5 and SHA hashes in C#.NET.
public static class CryptographyExtensions
{
/// <summary>
/// Calculates the MD5 hash for the given string.
/// </summary>
/// <returns>A 32 char long MD5 hash.</returns>
public static string GetHashMd5(this string input)
{
return ComputeHash(input, new MD5CryptoServiceProvider());
}
@rmacfie
rmacfie / Object.cshtml
Created July 31, 2012 20:49
Default object Editor Template ported to Razor (Asp.Net Mvc)
@{
Func<ModelMetadata, bool> shouldShow = metadata =>
{
return metadata.ShowForEdit
//&& metadata.ModelType != typeof(System.Data.EntityState)
&& !metadata.IsComplexType
&& !ViewData.TemplateInfo.Visited(metadata);
};
}
@if (ViewData.TemplateInfo.TemplateDepth > 1)
@rmacfie
rmacfie / gist:4512293
Last active December 10, 2015 23:49
StructureMap + MVC4 + WebApi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http.Dependencies;
using StructureMap;
public class StructureMapResolver : IDependencyScope, IDependencyResolver
{
private readonly IContainer _container;
private readonly bool _isContainerOwner;
@rmacfie
rmacfie / StructureMapNancyBootstrapper.cs
Last active August 29, 2015 14:00
Nancy bootstrapper with StructureMap (without just in time registrations)
public class StructureMapNancyBootstrapper : StructureMapNancyBootstrapperBase
{
public StructureMapNancyBootstrapper() : base(typeof(MyModule).Assembly)
{
}
protected override IContainer GetApplicationContainer()
{
return new Container();
}
@rmacfie
rmacfie / gist:2429c6e9bca7e0168cfd
Last active August 29, 2015 14:14
Boxstarter
choco install notepad2-mod
choco install conemu
choco install 7zip
choco install googlechrome
choco install kdiff3
choco install gitextensions
choco install git-credential-winstore
choco install nodejs
choco install visualstudiocode
@rmacfie
rmacfie / MediatRExtensions.cs
Last active July 12, 2022 12:42
Register MediatR handlers in Asp.Net 5 / vNext / Core
namespace Microsoft.AspNet.Builder
{
public static class MediatRExtensions
{
public static IServiceCollection AddMediatR(this IServiceCollection services, params Assembly[] handlerAssemblies)
{
services.AddTransient<IMediator>(x => new Mediator(x.GetService<SingleInstanceFactory>(), x.GetService<MultiInstanceFactory>()));
services.AddTransient<SingleInstanceFactory>(x => t => x.GetRequiredService(t));
services.AddTransient<MultiInstanceFactory>(x => t => x.GetServices(t));
@rmacfie
rmacfie / azure-msdeploy-folder.cmd
Last active November 14, 2015 18:16
Simple folder deploy through Web Deploy (MSDeploy)
:: The following variables are required:
SET AZDEPLOY_SOURCE=C:\Apps\myapp\dist
SET AZDEPLOY_APP=myapp
SET AZDEPLOY_PASSWORD=mypassword
:: The password can be extracted from the publish settings you download from the Azure portal
msdeploy.exe ^
-verb:sync ^
-source:contentPath="%AZDEPLOY_SOURCE%" ^
@rmacfie
rmacfie / DomainEnforcer.cs
Last active May 14, 2016 11:23
Enforce domain name in Asp.Net Core
using System;
namespace Microsoft.AspNet.Builder
{
public static class DomainEnforcer
{
public static IApplicationBuilder UseDomainEnforcer(this IApplicationBuilder app, string domainToEnforce)
{
if (string.IsNullOrEmpty(domainToEnforce))
throw new ArgumentNullException(nameof(domainToEnforce));
@rmacfie
rmacfie / HttpsEnforcer.cs
Last active May 14, 2016 11:22
Enforce HTTPS in Asp.Net Core
using System;
namespace Microsoft.AspNet.Builder
{
public static class HttpsEnforcer
{
public static IApplicationBuilder UseHttpsEnforcer(this IApplicationBuilder app)
{
Func<RequestDelegate, RequestDelegate> middleware = next => async context =>
{
@rmacfie
rmacfie / SimpleLogger.cs
Last active May 14, 2016 11:21
Simple request logging in Asp.Net Core, suitable for showing in the console while developing
using System;
using System.Diagnostics;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Builder
{
public static class SimpleLogger
{
const string LOG_NAME = "MyProject.SimpleLogger";
const string LOG_FORMAT = "{0} | {1}ms | {2} | {3} {4}";