Skip to content

Instantly share code, notes, and snippets.

View mikehadlow's full-sized avatar

Mike Hadlow mikehadlow

View GitHub Profile
FROM nornagon/postgres
MAINTAINER mike@suteki.co.uk
ADD sql sql
ADD create_db.sh /src/
USER postgres
RUN /src/create_db.sh
@mikehadlow
mikehadlow / IBus.cs
Created November 15, 2013 14:49
EasyNetQ's proposed new send/receive API. This is for sending messages explicitly to a named destination queue via the default exchange. The Receive call creates a consumer for the specified message type. Further calls to Receive with the same queue, but a different message type will add additional message handlers to the same consumer.
/// <summary>
/// Send a message directly to a queue
/// </summary>
/// <typeparam name="T">The type of message to send</typeparam>
/// <param name="queue">The queue to send to</param>
/// <param name="message">The message</param>
void Send<T>(string queue, T message);
/// <summary>
/// Receive messages from a queue.
@mikehadlow
mikehadlow / Astrology Smackdown
Created October 15, 2013 15:27
Somebody in the office was defending astrology. Their argument went something like this: You concede that the Moon is known to effect natural phenomena on Earth. Jupiter is a far larger body, although granted it is further away, so it must have some effect as well.
Newton's law of universal gravitation:
http://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation
F = G(m1 * m2)/r^2
Mass of the Earth: 5.97219 × 10^24 kg
Mass of the Moon: 7.3477 × 10^22 kg
Distance to the Moon (average): 384,400 km
@mikehadlow
mikehadlow / ManyWaysToStartAThread.cs
Last active December 24, 2015 13:49
The many ways to start a thread in .NET. Can you think of any more?
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Mike.Spikes.Threading
{
public class ManyWaysToStartAThread
{
public void WithThread()
{
@mikehadlow
mikehadlow / ClientCommandDispatcherTests.cs
Created October 1, 2013 11:30
Some tests for EasyNetQ's new ClientCommandDispatcher.
// ReSharper disable InconsistentNaming
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using EasyNetQ.ConnectionString;
using EasyNetQ.Loggers;
using EasyNetQ.Producer;
@mikehadlow
mikehadlow / SshWrapperTsets.fs
Created May 15, 2013 16:00
Rather pleased with my monadic SSH.NET wrapper
[<Test>]
[<Explicit>]
let ``get hostname`` () =
ssh (print <!> hostname)
[<Test>]
[<Explicit>]
let ``should be able to put a file on the nginx server`` () =
scp (putFile testFileName content)
ssh (reader {
@mikehadlow
mikehadlow / CameraOutput.cs
Created August 1, 2012 09:49
Attempting to capture iSight camera output
// from the QTRecorder sample application in the MonoMac source
// In QTRDocument contructor ....
// ---- Add image capture output
var decompressedVideoOuput = new QTCaptureDecompressedVideoOutput();
NSError error2;
decompressedVideoOuput.DidOutputVideoFrame += (sender, e) =>
{
// var frame = e.SampleBuffer;
@mikehadlow
mikehadlow / Euler.hs
Created June 9, 2011 08:19
Project Euler 1 to 10 in Haskell
import List
import Control.Applicative
euler1 = sum $ nub $ [3,6..999] ++ [5,10..999]
fib = let fib' a b = a : fib' b (a+b) in fib' 0 1
euler2 = sum . (filter even) . takeWhile (<4000000) $ fib
factor n = [x|x <- [2..(floor(sqrt(fromInteger n)))], n `mod` x == 0]
@mikehadlow
mikehadlow / WindsorExtensions.cs
Created May 27, 2011 14:09
A Windsor registration checking extension method
using System.Linq;
using Castle.Windsor;
namespace Suteki.Common.Windsor
{
public static class WindsorExtensions
{
public static void CheckRegistration<TService, TImplementation>(this IWindsorContainer container)
{
var handlers = container.Kernel.GetHandlers(typeof(TService));
@mikehadlow
mikehadlow / IoC.cs
Created February 8, 2011 10:05
My common service locator replacement
using System;
namespace Suteki.Common.Windsor
{
public class IoC
{
private static Func<Type, object> resolve;
private static Action<object> release;
public static T Resolve<T>()