Skip to content

Instantly share code, notes, and snippets.

@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
@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}}
<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>
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;
@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>()
@mikeobrien
mikeobrien / TrailingSlashRedirectBehavior.cs
Created November 26, 2012 02:48
Fubu Trailing Slash Behavior
public class TrailingSlashRedirectBehavior : IActionBehavior
{
private readonly IActionBehavior _innerBehavior;
private readonly IOutputWriter _outputWriter;
private readonly ICurrentHttpRequest _request;
public TrailingSlashRedirectBehavior(IActionBehavior innerBehavior, IOutputWriter outputWriter, ICurrentHttpRequest request)
{
_innerBehavior = innerBehavior;
_outputWriter = outputWriter;
@mikeobrien
mikeobrien / XmlFormatter.cs
Created November 30, 2012 23:41
Replace XML Serializer Fubu
public class Conventions : FubuRegistry
{
public Conventions()
{
Policies.Add(x => x.ModifyBy(y => y.AddSymmetricFormatter<MyNewXmlFormatter>(), ConfigurationType.Attachment));
}
}
public static class Extensions
{
@mikeobrien
mikeobrien / Extensions.cs
Created December 5, 2012 15:11
Get response extension
public static HttpWebResponse GetResponse(this HttpWebRequest request, bool throwHttpExceptions)
{
if (throwHttpExceptions) return (HttpWebResponse)request.GetResponse();
try
{
return (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
var response = e.Response as HttpWebResponse;
@mikeobrien
mikeobrien / gist:4525665
Created January 13, 2013 18:51
Fubu error when diagnostics are added
Source Error:
Line 13: public static void Start()
Line 14: {
Line 15: FubuApplication.For<Conventions>().StructureMap(new Container()).Bootstrap();
Line 16: PackageRegistry.AssertNoFailures();
Line 17: }
Source File: d:\Development\FubuMVC.Swank\src\TestHarness\Bootstrap.cs Line: 15
@mikeobrien
mikeobrien / gist:4525809
Created January 13, 2013 19:35
Bottles.XmlSerializers binding error
<meta http-equiv="Content-Type" content="charset=unicode-1-1-utf-8"><!-- saved from url=(0015)assemblybinder: --><html><pre>
*** Assembly Binder Log Entry (1/13/2013 @ 2:31:53 PM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\IIS Express\iisexpress.exe
--- A detailed error log follows.