Skip to content

Instantly share code, notes, and snippets.

public class FoodViewModel
{
public string FavouriteFood { get; set; }
}
public ActionResult UpdateFood(FoodViewModel viewModel)
{
if(ModelState.IsValid)
{
UpdateStats(viewModel.FavouriteFood);
@keithbloom
keithbloom / gist:3766612
Created September 22, 2012 16:00
AutoFixtureBug
Test 'Testy' failed: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
---- System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
-------- System.InvalidCastException : Unable to cast object of type 'Ploeh.AutoFixture.Kernel.OmitSpecimen' to type 'Language'.
at System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct& signature, RuntimeType declaringType)
at System.RuntimeMethodHandle.InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct signature, RuntimeType declaringType)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Ploeh.AutoFixture.Kernel.ConstructorMethod.Invoke(IEnumerable`1 parameters)
at Ploeh.AutoFixture.Kernel.MethodInvoker.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.FilteringSpecimenBuilder.Create(Ob
@keithbloom
keithbloom / ControllerDoWork.cs
Created September 10, 2012 15:17
0MQ and threads
var fileList = EnumerateDirectory(@"C:\example\directory", "*.*", SearchOption.AllDirectories);
ventilator.Run(fileList);
var result = sink.Run(fileList.Length);
Console.WriteLine("Found the length of {0} files in {1} milliseconds.\nDirectory size is {2}",
fileList.Length, stopWatch.ElapsedMilliseconds, result);
@keithbloom
keithbloom / TimeClient.cs
Created August 19, 2012 12:08
0MQ : Introduction
using (var context = new Context(1))
using (var client = context.Socket(SocketType.REQ))
{
client.Connect("tcp://localhost:5555");
var time = client.Send("", Encoding.Unicode);
Console.WriteLine(time);
}
@keithbloom
keithbloom / clean-nuget.ps
Created July 31, 2012 08:41
Use git status to remove unwanted files added by NuGet
git status --porcelain | select-string -pattern "\.dll|\.xml" | foreach-object { $_ -replace "\?\? "} | rm
@keithbloom
keithbloom / snippet1.bat
Created May 16, 2012 07:29
Roundhouse with a legacy database
sql-baseline -s:.\SqlExpress -d:AdventureWorks -o:..\Src\AdventureWeb\AdventureWeb.Database\db
@keithbloom
keithbloom / ListOfTables.sql
Created February 20, 2012 13:41
Using Extended Properties to limit the call to sp_msforeachtable
SELECT s.name [Schema], t.name [Table],
CAST(Value AS nvarchar(500)) AS [MS_Description]
FROM sys.extended_properties AS ep
JOIN sys.tables t
on ep.major_id = t.object_id
join sys.schemas s
on s.schema_id = t.schema_id
WHERE ep.name = N'MS_Description' AND ep.minor_id = 0
and LOWER(CAST(Value AS nvarchar(500))) like '%lookup%'
order by s.name, t.name
@keithbloom
keithbloom / example.cs
Created January 26, 2012 16:05
Using delegates to clean up multiple IF statements
private void RunValidation()
{
foreach (var propertyInfo in GetType().GetProperties())
{
var attribute = Attribute.GetCustomAttribute(propertyInfo, typeof(RequiredField)) as RequiredField;
if (attribute == null) continue;
/*
if (propertyInfo.PropertyType == typeof(string)
&& string.IsNullOrEmpty((string)propertyInfo.GetValue(this, null)))
@keithbloom
keithbloom / example1.cs
Created January 13, 2012 12:23
ReferencedAndLoadAssemblies
public void AssemblyLoad_tests()
{
// Display information about the EXE assembly.
var a = Assembly.GetExecutingAssembly();
Console.WriteLine("Assembly identity = {0}", a.FullName);
Console.WriteLine("\tLocation = {0}\n", a.Location);
// Display the set of assemblies our assemblies reference.
Console.WriteLine("Referenced assemblies:");
foreach (var an in a.GetReferencedAssemblies())
@keithbloom
keithbloom / example1.js
Created October 30, 2011 14:41
WonderfulBackboneJS
$(function() {
// 1
window.ShoppingItem = Backbone.Model.extend({
constructor: function () {
if (!this.collection) {
this.collection = Products;
}
},
defaults: {