Skip to content

Instantly share code, notes, and snippets.

View caevyn's full-sized avatar

Matt Murphy caevyn

  • Newcastle, Australia
View GitHub Profile
@caevyn
caevyn / gist:5133306
Last active December 14, 2015 18:59
Exclude sensitive form data from elmah logs
//in global.asax
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
var ctx = e.Context as HttpContext;
if(ctx == null)
{
return;
}
ElmahSensitiveDataFilter.Apply(e, ctx);
}
@caevyn
caevyn / gist:5772914
Created June 13, 2013 11:06
from davepermen.net i can now do this: http://localhost:7820/route/BlogModule and get back this [ "GET /", "GET /list/{pageId}", "GET /article/{id}", "GET /newArticle" ]
public class RouteModule : NancyModule
{
public RouteModule(IRouteCacheProvider routeCache)
{
Get["/routes/all"] = _ => routeCache.GetCache().Select(entry => new
{
Module = entry.Key.Name,
Routes = entry.Value.Select(route => route.Item2.Method + " " + route.Item2.Path)
});
Get["/route/{moduleName}"] = _ =>
@caevyn
caevyn / gist:6051595
Created July 22, 2013 06:01
ServiceStack AppHost Configure for metrics.
public override void Configure(Funq.Container container)
{
const string statsdPrefix = "Qas.Web";
//common config shared with tests
Config.Configure();
container.Register<IStatsd>(c => new Statsd(new StatsdUDP("localhost", 8125)));
Plugins.Add(new MetricsFeature(container.Resolve<IStatsd>(), statsdPrefix));
@caevyn
caevyn / ElmahSensitiveDataFilter.cs
Created January 16, 2014 05:38
Filter out sensitive info before it ends up in ELMAH
public static class ElmahSensitiveDataFilter
{
public static void Apply(ExceptionFilterEventArgs e, HttpContext ctx)
{
var sensitiveFormData = ctx.Request.Form.AllKeys.GetSensitiveFormData();
if (sensitiveFormData.Count == 0)
{
return;
}
var error = new Error(e.Exception, ctx);
@caevyn
caevyn / Web.config
Last active August 29, 2015 13:56
Separate encrypted app settings section
<configuration>
<configSections>
<section name="secureAppSettings" type="System.Configuration.NameValueSectionHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<secureAppSettings>
<add key="encryptMe" value="ImSuperSecret" />
</secureAppSettings>
</configuration>
@caevyn
caevyn / JsonLayoutRenderer
Last active August 29, 2015 13:57
Json layout renderer for nlog + rabbitMQ target + logstash
using System.Globalization;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using NLog.LayoutRenderers;
namespace Cats.Middleware.Logging
{
[LayoutRenderer("json")]
@caevyn
caevyn / app.conf
Last active August 29, 2015 13:58
logstash conf
input {
stdin { type => example }
file {
#any line not starting with a tleast 10 dashes belongs with the previous line
codec => multiline {
pattern => "^-{10,}"
negate => true
what => next
}
path => "C:/applogs/*.log"
@caevyn
caevyn / dodgylogparsing.rb
Last active August 29, 2015 13:58
From weird log format to hash. (for logstash filter)
log = "DateTime: 23/04/1998\r\nI'm just a message\r\nKey: value\r\nIm a url: http://cats.com\r\nError Description: I'm an error here is my stacktrace\r\n at stuff\r\n at more stuff\r\n\key with no value: \r\nI'm another random message line\r\n--------------------------------------------"
rows = log.split(/\r\n/).partition{|x| x.start_with?('Error Description: ',' at')}
event = {'Error'=>rows[0].join($/).sub('Error Description: ','')}
remove = []
rows[1].each do |i|
i.scan(/(.+): (.*)/) do |x,y|
event[x.delete(' ')] = y
remove.push(i)
end
@caevyn
caevyn / gatlingindex.js
Created July 2, 2014 02:07
node app to render an index for gatling reports
var express = require('express'),
finder = require('finder-on-steroids');
var app = express();
app.use(express.static('../results'));
app.listen(9085);
app.get('/', function(req, res, next) {
finder('../results').files().depth(2).name('index.html').find().then(function(files) {
@caevyn
caevyn / cloud_formation_test.json
Last active August 29, 2015 14:15
messing with cloud formation
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation demo thingy",
"Parameters" : {
"KeyName": {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the Elastic Beanstalk hosts",
"Type": "AWS::EC2::KeyPair::KeyName",