Skip to content

Instantly share code, notes, and snippets.

@mikeobrien
mikeobrien / BehaviorGraph.cs
Created November 14, 2012 16:23
Simple Behavior Graph
public interface IBehavior
{
void Execute<T>(T data);
}
public class BehaviorGraph
{
private readonly IList<Type> _behaviors = new List<Type>();
public T Execute<T>()
public static class ProcessExtensions
{
public static bool IsWindowsService(this Process process)
{
return process.GetParent().ProcessName == "services";
}
public static Process GetParent(this Process process)
{
var parentPid = 0;
<customBinding>
<binding name="ReachmailBuffered">
<security authenticationMode="UserNameOverTransport" includeTimestamp="false">
<secureConversationBootstrap />
</security>
<textMessageEncoding messageVersion="Soap11" maxReadPoolSize="209715200">
<readerQuotas maxStringContentLength="2147483647" />
</textMessageEncoding>
<httpsTransport maxReceivedMessageSize="209715200" maxBufferPoolSize="209715200" maxBufferSize="209715200" />
</binding>
@mikeobrien
mikeobrien / BlockHelpers.js
Created October 8, 2012 22:53
Handlebars conditional block helper
Handlebars.registerHelper('when', function (predicate, options) {
var declarations = '';
for (var field in this) declarations += field + ' = this.' + field + ',';
if (eval(declarations + predicate)) { return options.fn(this); }
});
{{#when 'admin || superUser'}}
crazy go nuts
{{/when}}
@mikeobrien
mikeobrien / fubu-bottles.rb
Created September 20, 2012 19:22
Fubu Bottle Rake Task
require "fileutils"
def create_fubu_bottle(*args, &block)
body = lambda { |*args|
task = CreateFubuBottle.new
block.call(task)
task.run
}
Rake::Task.define_task(*args, &body)
end
public class MemorySmtpServer
{
private readonly bool _redirectSmtpConfiguration;
private const int Port = 62352;
private readonly Configuration _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
private MailSettingsSectionGroup _mailSettings;
private string _originalHost;
private int _originalPort;
private SmtpServer _server;
@mikeobrien
mikeobrien / ExpandoJsonWriter.cs
Created July 17, 2012 02:20
Serialize Expando
public class ExpandoJsonWriter : IJsonWriter
{
private readonly IOutputWriter _outputWriter;
private readonly JavaScriptSerializer _jsonSerializer;
public ExpandoJsonWriter(IOutputWriter outputWriter)
{
_outputWriter = outputWriter;
_jsonSerializer = new JavaScriptSerializer();
}
[TestFixture]
public class Spark
{
public const string MasterTemplate = @"
<html>
<body>
<h1>TMNT</h1>
<div>{{{Content}}}
</div>
</body>
@mikeobrien
mikeobrien / NustacheSpecs.cs
Created July 11, 2012 22:10
Using Nustache
public class Mustache
{
public const string MasterTemplate = @"
<html>
<body>
<h1>TMNT</h1>
<div>{{{Content}}}
</div>
</body>
</html>";
public class Person
{
public string Name { get; set; }
public string Address { get; set; }
}
public class InputModel
{
public string GroupId { get; set; }
public Person Person { get; set; }