Skip to content

Instantly share code, notes, and snippets.

View jakcharlton's full-sized avatar

Jak Charlton jakcharlton

View GitHub Profile
@jakcharlton
jakcharlton / ruby_koans_scoring_benchmarks.rb
Created July 19, 2011 00:45
Benchmarking three versions of Ruby Koans scoring algorithm
require 'benchmark'
class Gary
# https://gist.github.com/1089115
def score(dice)
score_counts(dice).inject(0) {|score, pair| score + frequency_score(pair)}
end
def frequency_score(pair)
triple_score(pair) + single_score(pair)
@jakcharlton
jakcharlton / about_scoring_project.rb
Created July 18, 2011 05:29
About Scoring from Ruby Koans
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used to calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
@jakcharlton
jakcharlton / installer.cs
Created July 11, 2011 01:15
WindsorInstaller For Single Action Controllers
public void Install(IWindsorContainer container, IConfigurationStore store)
{
foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
{
if (typeof(IController).IsAssignableFrom(type) && !type.IsAbstract)
container.Register(Component.For(type).ImplementedBy(type).Named(type.FullName.ToLower()).LifeStyle.Transient);
}
}
@jakcharlton
jakcharlton / windsor.cs
Created July 11, 2011 01:13
SingleAction Windsor Controller Factory
public class WindsorControllerFactory : DefaultControllerFactory
{
private readonly IKernel kernel;
public WindsorControllerFactory(IKernel kernel)
{
this.kernel = kernel;
}
public override void ReleaseController(IController controller)
@jakcharlton
jakcharlton / singleactioncontroller.cs
Created July 11, 2011 01:12
MVC Single Action Controller
public class IndexController : Controller
{
[Authorize]
public ActionResult Index()
{
return View();
}
}
@jakcharlton
jakcharlton / .gitignore
Created June 29, 2011 04:40
Gitignore for .NET
*.obj
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
@jakcharlton
jakcharlton / comaprison.cs
Created June 15, 2011 06:17
Property equality comparison on two objects
// Shamelessly stolen and adapted from http://stackoverflow.com/questions/506096/comparing-object-properties-in-c
public static class Comparisons
{
public static bool PublicInstancePropertiesEqual<T>(this T self, T to, params string[] ignore) where T : class
{
if (self != null && to != null)
{
var type = typeof(T);
var ignoreList = new List<string>(ignore);
foreach (System.Reflection.PropertyInfo pi in type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
@jakcharlton
jakcharlton / fm.xml
Created June 15, 2011 01:41
Resharper File Template for FluentMigrations
<TemplatesExport family="File Templates">
<Template uid="188d3b0a-987e-48b4-b42a-2ebaa25b21fb" shortcut="" description="Fluent Migration" text="using FluentMigrator;&#xD;&#xA;&#xD;&#xA;namespace $NAMESPACE$&#xD;&#xA;{&#xD;&#xA; [Migration($MIGRATIONNUMBER$)]&#xD;&#xA; public class $CLASS$$MIGRATIONNUMBER$ : Migration&#xD;&#xA; {&#xD;&#xA; public override void Up()&#xD;&#xA; {&#xD;&#xA; $END$&#xD;&#xA; }&#xD;&#xA;&#xD;&#xA; public override void Down()&#xD;&#xA; {&#xD;&#xA;&#xD;&#xA; }&#xD;&#xA; }&#xD;&#xA;}&#xD;&#xA;" reformat="True" shortenQualifiedReferences="True">
<Scopes>
<Scope type="Everywhere" />
</Scopes>
<Categories />
<Variables>
<Variable name="NAMESPACE" expression="fileDefaultNamespace()" initialRange="0" />
<Variable name="MIGRATIONNUMBER" expression="getCurrentTime(&quot;yyyymmddhhss&quot;)" initialRange="0" />
<Variable name="CLASS" expression="getFileNameWithoutExtension()" initialRange="
CanCreateTable : FailedSetUp : System.BadImageFormatException : is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Data.SqlServerCe.UnmanagedLibraryHelper..ctor(String fileName)
at System.Data.SqlServerCe.NativeMethodsHelper..ctor(String modulePath)
at System.Data.SqlServerCe.NativeMethods.LoadValidLibrary(String modulePath)
at System.Data.SqlServerCe.NativeMethods.LoadNativeBinariesFromPrivateFolder(String privateInstall)
at System.Data.SqlServerCe.NativeMethods.LoadNativeBinaries()
at System.Data.SqlServerCe.SqlCeEngine..ctor()
at System.Data.SqlServerCe.SqlCeEngine..ctor(String connectionString)
Buildfile: file:///C:/dev2/fmce/src/FluentMigrator.Example/example-nant.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: migrate
[loadtasks] Scanning assembly "FluentMigrator.NAnt" for extensions.
migrate:
Using Database SqlServerCe and Connection String Data Source=Database1.sdf
-- Beginning Transaction