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 / 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 / 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 / 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 / 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 / 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 / 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:990150
Created May 25, 2011 01:31
Petapoco Dbparameter
_databaseQuery.Execute("insert into temp1 (t) values (@0)"
, new SqlParameter() { SqlDbType = SqlDbType.VarBinary, Value = new byte[] {12, 1, 34, 234}});
@schotime
schotime / gist:977737
Created May 18, 2011 00:13
PetaPoco StructureMap
//This is how I use PetaPoco with structure map but I'm also using the IDatabase interface from my branch at http://github.com/schotime/petapoco
public class PetaPocoRegistry : Registry
{
public PetaPocoRegistry()
{
Scan(x =>
{
x.TheCallingAssembly();
x.WithDefaultConventions();
@schotime
schotime / gist:966339
Created May 11, 2011 12:03
Example petapoco use
public class Security
{
public int SecurityId { get; set; }
public string Name { get; set; }
}
public class User
{
public int UserId { get; set; }
public string FirstName { get; set; }
@schotime
schotime / gist:961304
Created May 8, 2011 11:02
glimpse workaround
var sql = "!" + application.Server.HtmlEncode(item.Sql).Replace("] ", "&#93; ") + "!"; //Glimpse Sanitizer workaround