Skip to content

Instantly share code, notes, and snippets.

var result = Controller.Create(...);
result.ShouldBeRedirectTo("Customers", "Index");
// instead of:
var result = Controller.Create(...);
var redirectResult = result as RedirectResult;
@jagregory
jagregory / ArrayModelBinder.cs
Created January 4, 2011 13:29
Custom MVC1 model binder that handles array properties
public class ArrayModelBinder : IFilteredPropertyBinder
{
private static readonly Regex IdRegex = new Regex("(?<=_)[0-9]+(?=_)");
public bool IsMatch(Type modelType)
{
return modelType.IsArray;
}
public void BindProperty(IModelBinder binder, ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)
@jagregory
jagregory / License.txt
Created December 16, 2010 14:16
jQuery require function
/**
* jQuery.require - Require/include plugin for including necessary scripts
*
* Copyright (c) 2010, James Gregory (james@jagregory.com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that
* the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list of conditions and the
@jagregory
jagregory / validate.js
Created December 7, 2010 17:04
Custom ajax "unique" validator with reason in response
var validator = $('form').validate({
rules: {
number: {
remote: {
url: 'UniqueNumber',
dataType: 'json',
success: function(data) {
if (data.unique == true) {
return;
}
@jagregory
jagregory / gist:710671
Created November 22, 2010 21:01
How to move to a fork after cloning
So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!
Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.
* Off the top of my head *
1. Fork their repo on Github
2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it
git remote add my-fork git@github...my-fork.git
public class SomeService
{
public string GetValues()
{
return "huzzah";
}
}
public class Person
{
Fluent Mappings
---------------
Sources scanned:
Examples.FirstProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Mappings discovered:
EmployeeMap | Examples.FirstProject.Mappings.EmployeeMap, Examples.FirstProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Fluently.Configure()
.Mappings(...)
.Database(...)
.Diagnostics(dia =>
{
dia.Enable();
dia.OutputToConsole();
})
.BuildSessionFactory();
public static class RhinoMocksExtensions
{
public static IMethodOptions<IEnumerable<T>> ReturnEmptySet<T>(this IMethodOptions<IEnumerable<T>> options)
{
return options.Return(new T[0]);
}
}
public class MyAutomappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Member member)
{
return base.ShouldMap(member) && member.CanWrite;
}
}