Skip to content

Instantly share code, notes, and snippets.

View gshutler's full-sized avatar
📅
👨‍💻

Garry Shutler gshutler

📅
👨‍💻
View GitHub Profile
public static class ServiceBusExtensions
{
public static bool HasSubscribersFor<T>(this IServiceBus serviceBus, T message)
{
IEnumerable<Action<object>> enumerable = serviceBus.OutboundPipeline.Enumerate(message);
return enumerable.Any();
}
}
<html>
<head></head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("button").click(function() {
$("form").append(
$("<input />")
.attr("type", "hidden")
$(".container").each(function() {
var that = $(this);
that.find("img").load(function() {
that.append("<span>" + $(this).height() + "</span>");
});
});
var elementsToHash = function(elements) {
var hash = {};
elements.each(function() {
var element = $(this);
hash[element.attr("name")] = element.val();
});
return hash;
}
public static class ConventionHelper
{
public static string PluralUnderscore(string name)
{
return Underscore(Inflector.Net.Inflector.Pluralize(name));
}
public static string Underscore(string name)
{
return Regex.Replace(name, "([a-z])([A-Z])", "$1_$2").ToLowerInvariant().Trim();
@gshutler
gshutler / EntityMap.cs
Created April 2, 2010 21:31
Demonstration of how to back a GUID with a string column with Fluent NHibernate
using FluentNHibernate.Mapping;
using Custom.Domain;
using Custom.Mappings.UserTypes;
namespace Custom.Mappings
{
public abstract class EntityMap<T> : ClassMap<T> where T : Entity
{
protected EntityMap()
{
class Encrypted<T>
{
readonly byte[] value;
T decrypted;
public Encrypted(byte[] value)
{
this.value = value;
}
using System;
namespace Currying
{
public static class Fn
{
public static Func<Func<int>, Func<int>> Curry(Func<Func<int>, Func<int>> x, Func<Func<int>, Func<int>> y)
{
return a => y(x(a));
}
@gshutler
gshutler / ObjectSetterExtensions.cs
Created April 15, 2010 15:29
Extension method for setting non-public properties in tests
public static class ObjectSetterExtensions
{
public static TValue SetProperty<T, TValue>(this T target, Expression<Func<T, TValue>> property, TValue value)
{
var propertyName = property.GetPropertyName();
var propertySetter = typeof (T).GetProperty(propertyName).GetSetMethod(true);
propertySetter.Invoke(target, BindingFlags.NonPublic, null, new object[] {value}, null);
return value;
require 'fileutils'
require 'tmpdir'
include FileUtils
class TempDirectory
def self.scoped(root = TempDirectory.timestamp_directory_name)
temp_dir = new(root)
yield temp_dir if block_given?