Skip to content

Instantly share code, notes, and snippets.

View schotime's full-sized avatar

Adam Schroder schotime

  • Melbourne, Australia
View GitHub Profile
@schotime
schotime / gist:1113211
Created July 29, 2011 06:02
ValidationBehavior<T>
public class ValidationBehavior<T> : BasicBehavior where T : class
{
IFubuRequest request;
IChainResolver chain;
ContinuationHandler continuation;
public ValidationBehavior(IFubuRequest request, IChainResolver chain, ContinuationHandler continuation) : base(PartialBehavior.Executes)
{
this.request = request;
this.chain = chain;
@schotime
schotime / gist:1113267
Created July 29, 2011 06:15 — forked from jmarnold/IModelTypeCoordinator.cs
ValidationBehavior<T>
public class ValidationBehavior<T> : BasicBehavior where T : class
{
IFubuRequest request;
IChainResolver chain;
IPartialFactory _factory;
public ValidationBehavior(IFubuRequest request, IChainResolver chain, IPartialFactory factory) : base(PartialBehavior.Executes)
{
this.request = request;
this.chain = chain;
@schotime
schotime / SqlBuilder.cs
Created September 8, 2011 00:24
Dynamic Sql based on templates
public class SqlBuilder
{
Dictionary<string, Clauses> data = new Dictionary<string, Clauses>();
int seq;
class Clause
{
public string Sql { get; set; }
public List<object> Parameters { get; set; }
}
@schotime
schotime / pluginrunner.cs
Created January 8, 2012 01:16
Plugin Runner
public interface IActivity
{
void Run();
bool Matches(int i);
}
public class PluginRunner
{
private readonly IContainer _container;
private readonly ILogger _logger;
@schotime
schotime / pluginrunner.cs
Created January 8, 2012 05:53 — forked from jmarnold/pluginrunner.cs
Plugin Runner
public interface IActivity
{
void Run();
bool Matches(int i);
}
public class PluginCoordinator
{
private readonly IPluginActivator _activator;
private readonly PluginRunner _pluginRunner;
@schotime
schotime / GuidComb.cs
Created February 13, 2012 04:00
Guid PK Petapoco
public static class GuidComb
{
public static Guid NewGuid()
{
byte[] b = Guid.NewGuid().ToByteArray();
DateTime dateTime = new DateTime(1900, 1, 1);
DateTime now = DateTime.Now;
TimeSpan timeSpan = new TimeSpan(now.Ticks - dateTime.Ticks);
TimeSpan timeOfDay = now.TimeOfDay;
byte[] bytes1 = BitConverter.GetBytes(timeSpan.Days);
@schotime
schotime / gist:2395851
Created April 16, 2012 01:19
Delegating Controller
public class HomeController : DelegatingControllers.DelegatingController
{
public ActionResult Edit(UserEditQueryModel model)
{
var vm = Invoker.Execute<UserEditQueryModel, UserEditViewModel>(model);
return View(vm);
}
public ActionResult Edit(UserEditInputModel model)
@schotime
schotime / global.asax.cs
Created June 20, 2012 02:00
FluentValidation Localization Adapter
public class FluentValidationKeys : StringToken
{
public static StringToken CREDITCARD_ERROR = new FluentValidationKeys("'{PropertyName}' is not a valid credit card number.");
public static StringToken EMAIL_ERROR = new FluentValidationKeys("'{PropertyName}' is not a valid email address.");
public static StringToken EQUAL_ERROR = new FluentValidationKeys("'{PropertyName}' should be equal to '{PropertyValue}'.");
public static StringToken EXACT_LENGTH_ERROR = new FluentValidationKeys("'{PropertyName}' must be {MaxLength} characters in length. You entered {TotalLength} characters.");
public static StringToken EXCLUSIVEBETWEEN_ERROR = new FluentValidationKeys("'{PropertyName}' must be between {From} and {To} (exclusive). You entered {Value}.");
public static StringToken GREATERTHAN_ERROR = new FluentValidationKeys("'{PropertyName}' must be greater than '{ComparisonValue}'.");
public static StringToken GREATERTHANOREQUAL_ERROR = new FluentValidationK
@schotime
schotime / BindingExtensions.cs
Last active October 8, 2015 11:18
Spark Optional Attributes
public static class BindingExtensions
{
public static HtmlTag Data(this HtmlTag html, Dictionary<string, object> dataattrs)
{
foreach (var item in dataattrs)
{
html.Data(item.Key, item.Value);
}
return html;
}
@schotime
schotime / Deadlock.sql
Last active October 26, 2017 08:43
Reproduction of Deadlock on Select in Sql Server
create database deadlocktest
go
SELECT snapshot_isolation_state_desc from sys.databases where name='deadlocktest'
go
--ensure this is off: If Not do the following alters
ALTER DATABASE deadlocktest
SET ALLOW_SNAPSHOT_ISOLATION OFF
go