Skip to content

Instantly share code, notes, and snippets.

@runesoerensen
runesoerensen / AppHarborMiddleware.cs
Created June 14, 2014 01:12
Sample OWIN middleware that modifies requests based on standard nginx headers (used on AppHarbor)
public class AppHarborMiddleware : OwinMiddleware
{
public AppHarborMiddleware(OwinMiddleware next)
: base(next)
{
}
public override Task Invoke(IOwinContext context)
{
if (string.Equals(context.Request.Headers["X-Forwarded-Proto"], "https", StringComparison.InvariantCultureIgnoreCase))
@runesoerensen
runesoerensen / gist:8884870
Created February 8, 2014 14:52
New Relic deployment notification using AppHarbor configuration
using (var webClient = new WebClient())
{
var appSettings = ConfigurationManager.AppSettings;
webClient.Headers.Add("x-license-key", appSettings["NEWRELIC_LICENSEKEY"]);
webClient.UploadValues(new Uri("https://api.newrelic.com/deployments.xml"), new NameValueCollection
{
{ "deployment[app_name]", "My Application" },
{ "deployment[user]", "AppHarbor" },
{ "deployment[description]", string.Format("Deployment notification from {0}", appSettings["appharbor.worker_name"]) },
{ "deployment[revision]", appSettings["appharbor.commit_id"] },
@runesoerensen
runesoerensen / Program.cs
Created June 26, 2013 17:51
Sample console app that redirects stdout and stderr from another process to the current error and output streams
public class Program
{
public static void Main(string[] args)
{
var processStartInfo = new ProcessStartInfo
{
FileName = "C:\\foo.exe",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
@runesoerensen
runesoerensen / .gitignore
Created January 30, 2013 22:50
Default .gitignore when creating repository in VS2012 with Git support
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
[Oo]bj/
# mstest test results
TestResults
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
using System.IO;
using System.Security.Cryptography.X509Certificates;
namespace CertificateFoo
{
class Program
{
static void Main(string[] args)
{
using (var certificateStream = GetEmbeddedResourceStream<Program>("foo.p12"))
@runesoerensen
runesoerensen / RequireHttpsAttribute.cs
Created April 12, 2011 16:40
RequireHttpsAttribute using X-Forwarded-Proto header
using System;
using System.Web.Mvc;
using RequireHttpsAttributeBase = System.Web.Mvc.RequireHttpsAttribute;
namespace AppHarbor.Web
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true,
AllowMultiple = false)]
public class RequireHttpsAttribute : RequireHttpsAttributeBase
{
@runesoerensen
runesoerensen / ToPublicUrl.cs
Created January 30, 2011 22:49
Builds a public URL when IIS is behind a load balancer
public static string ToPublicUrl(this UrlHelper urlHelper, Uri relativeUri)
{
var httpContext = urlHelper.RequestContext.HttpContext;
var uriBuilder = new UriBuilder
{
Host = httpContext.Request.Url.Host,
Path = "/",
Port = 80,
Scheme = "http",