Skip to content

Instantly share code, notes, and snippets.

View mikehadlow's full-sized avatar

Mike Hadlow mikehadlow

View GitHub Profile
using System;
using System.Collections.Generic;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.Resolvers.SpecializedResolvers;
using Castle.Windsor;
namespace Mike.Spikes
{
public class WindsorCircularArrayRefs
{
using System;
using System.Collections.Generic;
using System.Linq;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
namespace Mike.Spikes
{
public class CanResolveByGenericTypeConstraints
{
@mikehadlow
mikehadlow / Geolocation.htm
Created November 17, 2010 10:35
HTML5 / Google maps api, Get the long name of the current user's coujntry
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Geolocation Demo</title>
<script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="Geolocation.js" type="text/javascript"></script>
<style type="text/css">
body
@mikehadlow
mikehadlow / Suteki.EventBus.js
Created January 19, 2011 16:18
A simple javascript event bus
var Suteki = Suteki || {};
Suteki.new_eventBus = (function(){
var self = {};
var subscriptions = {};
var unsubscribeTokens = [];
var subscriptionPointers = [];
@mikehadlow
mikehadlow / Suteki.TestRunner.js
Created January 20, 2011 12:22
A little javascript test runner for node.js
// run unit tests in node like this:
// node Suteki.TestRunner.js
//
// Unit tests should be named like this:
// Suteki.<name target>.Tests.js
//
// A test looks like this:
//
// (function(){
//
@mikehadlow
mikehadlow / Identity.cs
Created January 25, 2011 23:14
The simplest possible Monad in three languages: C#, F# and Haskell
using System;
namespace Suteki.Monads
{
public class FunctionComposition
{
public void AddTwoNumbers()
{
var result =
from a in 3.ToIdentity()
@mikehadlow
mikehadlow / UserTypeSpike.cs
Created February 7, 2011 10:08
Fluent NHibernate failing test (can insert into FluentNHibernate.Testing and run)
using System;
using System.Data;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Conventions;
using FluentNHibernate.Mapping;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.SqlTypes;
using NHibernate.Tool.hbm2ddl;
@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>()
@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 / 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]