Skip to content

Instantly share code, notes, and snippets.

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@beppemarazzi
beppemarazzi / JsonDocumentDestructuringPolicy.cs
Last active March 12, 2025 16:24 — forked from nblumhardt/JsonDocumentDestructuringPolicy.cs
Properly serialize System.Text.Json documents with Serilog
using System;
using System.Linq;
using System.Text.Json;
using Serilog.Core;
using Serilog.Events;
class JsonDocumentDestructuringPolicy : IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory _, out LogEventPropertyValue result)
{
@gertjvr
gertjvr / CorrelationExample.cs
Last active October 14, 2022 14:28
MT3 + Serilog CorrelationId Enricher.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Threading.Tasks;
using MassTransit;
using MassTransit.Configurators;
using MassTransit.PipeBuilders;
using MassTransit.PipeConfigurators;
using MassTransit.Pipeline;
@liammclennan
liammclennan / README.md
Last active April 17, 2020 18:29
RedisMQ

RedisMQ

Many people use Redis for a simple message broker. RedisMQ is a trivial layer on Redis and StackExchange.Redis that probably does not work. It provides two simple messaging patterns:

Publish / subscribe

A publisher publishes messages. 0, 1 or more consumers subscribe to the messages.

@tsimbalar
tsimbalar / README.md
Last active April 20, 2019 21:50
Pino js tool to make raw pino output compatible with Seq / GELF ingestion through docker

This is a small tool that allows transforms logs written with pino in newline-delimited JSON on the standard output to the Compact Log Event Format (CLEF) supported by the Seq logging server.

Typical use case for this is :

  • write your logs with pino how you would normally do it
logger.info({some: 'extra', context:'info'}, 'this is the message');
logger.info({user: 'John', amount:'2345', extra: 'other info'}, '{user} just spent {amount} euros on the website');
@PaulStovell
PaulStovell / Bootstrapper.cs
Created May 9, 2013 10:03
The Octopus Nancy error handling strategy
protected override void RequestStartup(ILifetimeScope requestContainer, IPipelines pipelines, NancyContext context)
{
pipelines.OnError.AddItemToEndOfPipeline((z, a) =>
{
log.Error("Unhandled error on request: " + context.Request.Url + " : " + a.Message, a);
return ErrorResponse.FromException(a);
});
base.RequestStartup(requestContainer, pipelines, context);
}
@bradwilson
bradwilson / vs2017.ps1
Last active January 23, 2018 19:05
VS 2017 PowerShell script; if you need invoke-cmdscript, it's here: https://gist.github.com/bradwilson/3fca203370d54304eff1cce21ffc32aa
param(
[string]$edition,
[switch]$noWeb = $false
)
# Try and find a version of Visual Studio in the expected location, since the VS150COMNTOOLS environment variable isn't there any more
$basePath = join-path (join-path ${env:ProgramFiles(x86)} "Microsoft Visual Studio") "2017"
if ((test-path $basePath) -eq $false) {
write-warning "Visual Studio 2017 is not installed."
@dennisroche
dennisroche / Install-Seq.ps1
Last active February 23, 2017 19:30
Download and install Seq (https://getseq.net/). Can be used by Azure Resource Manager template. Use RawGit to access the file with proper Content-Type headers - https://rawgit.com/
[CmdletBinding()]
param (
[string]$SeqVersion,
[string]$SeqInstanceName,
[string]$SeqPort
)
$installBasePath = "C:\Install\"
$seqDataPath = "C:\ProgramData\Seq"
@lukehorvat
lukehorvat / interceptors.coffee
Last active December 23, 2015 02:49
An example of how to use request/response interceptors in AngularJS 1.2 for consistent API interactions. This code does two things: 1) Automatic injection of the user auth token in all API requests. 2) Automatic event firing when the user receives an API response indicating a 401 (unauthorised) request.
.config ($httpProvider) ->
$httpProvider.interceptors.push ($q, $rootScope, apiUrl, authToken) ->
request: (config) ->
# Intercept API requests and inject the auth token.
config.headers["X-Auth-Token"] = authToken if config.url.indexOf(apiUrl) is 0 and authToken?
config or $q.when config
responseError: (response) ->
# Intercept unauthorised API responses and fire an event.
@dahlbyk
dahlbyk / gist:1102893
Created July 24, 2011 18:09
Rx Sliding Window
static IObservable<string> CheckForFraud(IObservable<string> logins)
{
return from g in logins.GroupByUntil(l => l, CheckForFraud)
from c in g.Count()
where c >= 3
select g.Key;
}
static IObservable<Unit> CheckForFraud(IGroupedObservable<string, string> g)
{