Skip to content

Instantly share code, notes, and snippets.

View mikeminutillo's full-sized avatar
🏠
Working from home

Mike Minutillo mikeminutillo

🏠
Working from home
View GitHub Profile
@mikeminutillo
mikeminutillo / IndexableProperties.linq
Last active May 11, 2021 05:21
Using a very basic algorithm to extract ids from serialized messages. Running this on my my machine reports 6.662 ms per message (117,870 bytes) for Json messages and 11.328 ms per message (165,034 bytes) for xml
<Query Kind="Program">
<NuGetReference>Newtonsoft.Json</NuGetReference>
<NuGetReference>System.Text.Json</NuGetReference>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>System.Text.Json</Namespace>
<Namespace>System.Xml.Serialization</Namespace>
</Query>
void Main()
{
@mikeminutillo
mikeminutillo / OwinExtensions.cs
Created February 11, 2020 03:55
Hosting ServicePulse from a zip within ServiceControl
using System.Net;
using Owin;
static class OwinExtensions
{
public static IAppBuilder RedirectRootTo(this IAppBuilder app, string destination)
{
app.Use(async (ctx, next) =>
{
if (ctx.Request.Path.Value == "/")
@mikeminutillo
mikeminutillo / Extensions.cs
Created May 23, 2018 03:48
Linearly Interpolate values in an enumerable stream of decimals
public static class Ext
{
private static IEnumerable<decimal> LinearInterpolate(decimal lowerBound, decimal upperBound, int pointCount)
{
var gradient = (upperBound - lowerBound) / (pointCount + 1);
for(var i = 1; i <= pointCount; i++)
{
yield return lowerBound + gradient * i;
}
}
@mikeminutillo
mikeminutillo / 1.Messages.cs
Last active May 24, 2017 08:52
Run a process every midnight that gathers some data and publishes an event
// Used to kick off the scheduler whenever the endpoint starts
class StartSchedulerCommand : ICommand
{
public Guid Key { get; set; }
}
// The scheduler saga sends one of these every midnight
class RunProcessCommand : ICommand
{
}
@mikeminutillo
mikeminutillo / EchoSatellite.cs
Created February 14, 2017 09:11
Nsb V5 satellite that just repeats what it gets sent
class EchoSatellite : ISatellite
{
public bool Handle(TransportMessage message)
{
string replyToAddress;
if (message.Headers.TryGetValue(Headers.ReplyToAddress, out replyToAddress))
{
dispatcher.Send(message, new SendOptions(replyToAddress));
return true;
}
@mikeminutillo
mikeminutillo / PublishHandledEventsAtStartup.cs
Created December 13, 2016 03:39
NServiceBus 6 feature. When enabled in an endpoint this feature will report all event types that can be handled to the console at startup.
class PublishHandledEventsAtStartup : Feature
{
protected override void Setup(FeatureConfigurationContext context)
{
var conventions = context.Settings.Get<Conventions>();
context.RegisterStartupTask(b =>
{
var handlerRegistry = b.Build<MessageHandlerRegistry>();
return new PublishedHandledEventsToConsole(handlerRegistry.GetMessageTypes().Where(conventions.IsEventType));
@mikeminutillo
mikeminutillo / RequestTracing.cs
Created October 14, 2016 05:15
NSB v6 Accept Test Request Tracing
static class RequestTracing
{
public static void EnableRequestTracing(this EndpointConfiguration cfg)
{
cfg.Pipeline.Register(typeof(LogIncomingBehavior), "Log incoming messages");
cfg.Pipeline.Register(typeof(LogOutgoingBehavior), "Log outgoing messages");
}
class LogOutgoingBehavior : Behavior<IDispatchContext>
{
@mikeminutillo
mikeminutillo / PipelineInspector.cs
Last active August 11, 2016 03:40
NServiceBus v5 Pipeline Inspector
public class PipelineInspector : IWantToRunWhenBusStartsAndStops
{
private readonly ReadOnlySettings settings;
public PipelineInspector(ReadOnlySettings settings)
{
this.settings = settings;
}
public void Start()
@mikeminutillo
mikeminutillo / ProjectDependencies.cs
Created June 12, 2015 01:25
Get project dependency graph out using yuml.me and LINQPad
void Main()
{
var ignores = new Regex[]
{
new Regex(@"Approval"),
new Regex(@"Test"),
new Regex(@"Demo")
};
var serviceControl = @"C:\Code\Particular\ServiceControl\src\";
Util.Image("http://yuml.me/diagram/scruffy;scale:150/class/" + String.Join(",", GetDependencies(serviceControl, ignores))).Dump();
@mikeminutillo
mikeminutillo / ExtractUsernameAndPasswordAsStoredByIE11.cs
Created February 5, 2015 08:19
A LINQPad Script which will retrieve the stored password that IE autocomplete saved against a particular url.
// With massive help from http://securityxploded.com/iepasswordsecrets.php
var urlBytes = System.Text.Encoding.Unicode.GetBytes((url + '\0').ToLower());
byte[] hashBytes;
using(var sha1 = new SHA1Managed())
hashBytes = sha1.ComputeHash(urlBytes);
var checksum = hashBytes.Aggregate((x,y) => (byte)((int)x + (int)y));
var keyBytes = hashBytes.Concat(new[] { checksum }).ToArray();
var regKey = String.Join("", keyBytes.Select(x => x.ToString("X2")));