Skip to content

Instantly share code, notes, and snippets.

View codescribler's full-sized avatar

Daniel Whittaker codescribler

View GitHub Profile
@codescribler
codescribler / MakeEvent from Command
Created June 20, 2012 08:44
Makes an event from the provided command - see gregory young's stuff on CQRS
protected TE MakeEvent<TE>(Command command)
where TE : Event
{
return MakeEvent<TE>(command, new List<object>());
}
private TE MakeEvent<TE>(Command command, IEnumerable<object> additionalParams)
where TE : Event
{
var type = typeof(TE);
@codescribler
codescribler / wysihtml5 ko binding handler
Created August 29, 2012 10:30
A binding handler for binding knockout observables to a wysihtml5 editor
ko.bindingHandlers.wysihtml5 = {
control: "",
init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
control = $(element).wysihtml5({
"events": {
"change" : function() {
var observable = valueAccessor();
observable(control.getValue());
}
}
@codescribler
codescribler / InMemoryDocumentStore
Created April 3, 2013 10:14
In memory raven db helper code with addition of index to cover all docs to allow for a purge of the db between tests.
public class InMemoryDocumentStore : IDocumentStoreConnection
{
public InMemoryDocumentStore()
{
Store = new EmbeddableDocumentStore()
{
RunInMemory = true
};
Store.RegisterListener(new NoStaleQueries());
Store.Initialize();
public class TestRootPathProvider : IRootPathProvider
{
private static string _cachedRootPath;
public string GetRootPath()
{
//return @"C:\Applications\51\DeliveryDateCalculator\StandAndDeliver\Views\Home\";
if (!string.IsNullOrEmpty(_cachedRootPath))
return _cachedRootPath;
@codescribler
codescribler / NancyFX easy default model access
Created June 3, 2013 13:20
An extension to make getting at the defaultModel from a nancyfx call easy to get to.
public static class Extensions
{
public static dynamic DefaultModel(this BrowserResponse response)
{
return response.Context.NegotiationContext.DefaultModel;
}
}
@codescribler
codescribler / Error Controller
Created August 13, 2013 09:58
A small collection of code for capturing client side javascript errors.
public class ErrorController : Controller
{
[HttpPost]
public JsonResult Record(ErrorInputModel model)
{
var ex = new ClientErrorException(model.ToString());
var signal = ErrorSignal.FromCurrentContext();
signal.Raise(ex);
@codescribler
codescribler / window on error
Created August 13, 2013 10:10
A javascript function to hook up the on error event to post the error to my server side logger.
<script>
window.onerror = function (errorText, url, lineNumber) {
var report = {
errorText: errorText,
url: url,
lineNumber: lineNumber
};
$.ajax({
type: "POST",
public class Scribe
{
public void SaveMessage(string file, string data)
{
if (File.Exists( file )) // How do you test this code??
{
throw new Exception("File name must be unique");
}
File.WriteAllText(path, data);
public class FileService : IWrapFile
{
public bool Exists(string path)
{
return File.Exists(path);
}
public void WriteAllText(string path, string contents)
{
File.WriteAllText(path, contents);
public class Scribe2
{
private IWrapFile fileService;
public Scribe2(IWrapFile file)
{
fileService = file;
}
public void SaveMessage(string file, string data)