Skip to content

Instantly share code, notes, and snippets.

@Rammesses
Rammesses / proxy.json
Last active June 18, 2020 18:08
Example proxy.json for Azure Functions adding security headers
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"StaticContent": {
"matchCondition": {
"route": "/web/{*path}",
"methods": [
"GET",
"HEAD"
]
public interface IMyInterface
{
}
public interface IMyInterface<T>
{
Type TargetType { get } => typeof(T);
}
@Rammesses
Rammesses / GoodJsonHelper.cs
Last active April 10, 2019 13:14
The correct way to add a custom converter to Newtonsoft JsonConvert
/// <summary>
/// The correct way to add a custom converter to Newtonsoft JsonConvert
/// </summary>
public static class JsonHelper
{
private static readonly object Padlock = new object();
private static readonly JsonSerializerSettings DefaultSettings = new JsonSerializerSettings();
private static Func<JsonSerializerSettings> GetDefaultSettings => () => DefaultSettings;
public static void AddJsonNetConverters()
@Rammesses
Rammesses / BadJsonHelper.cs
Created April 9, 2019 07:48
How *not* to add a converter to `JsonConvert.DefaultSettings`
/// <summary>
/// How *NOT* to add a custom converter to Newtonsoft JsonConvert
/// </summary>
public static class JsonHelper
{
public static void AddJsonNetConverters()
{
var defaultSettings = JsonConvert.DefaultSettings;
JsonConvert.DefaultSettings = () =>
{

Keybase proof

I hereby claim:

  • I am rammesses on github.
  • I am rammesses (https://keybase.io/rammesses) on keybase.
  • I have a public key ASCs_i9WARyYasJiCb203VKH4UhI5wvT28eATlNzrrCiFwo

To claim this, I am signing this object:

@Rammesses
Rammesses / SecurityHeadersLambda.js
Created November 9, 2017 09:26
AWS Lambda function to add standard security headers to a web site served from S3 and CloudFront.
'use strict';
exports.handler = (event, context, callback) => {
const response = event.Records[0].cf.response;
const headers = response.headers;
const hstsName = 'Strict-Transport-Security';
const hstsValue = 'max-age=31536000; includeSubDomains';
headers[hstsName.toLowerCase()] = [{
@Rammesses
Rammesses / WebHelp.cs
Created July 30, 2012 11:12
Super Secret Magic Sauce for adding an endpoint
public class WebHttpBehavior : IEndpointBehavior, IWmiInstanceProvider
{
public virtual void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
if (this.HelpEnabled)
{
HelpPage helpPage = new HelpPage(this, endpoint.Contract);
DispatchOperation dispatchOperation = new DispatchOperation(endpointDispatcher.DispatchRuntime, "HelpPageInvoke", (string) null, (string) null)