Skip to content

Instantly share code, notes, and snippets.

View davybrion's full-sized avatar

Davy Brion davybrion

  • That Extra Mile
  • Belgium
View GitHub Profile
@davybrion
davybrion / s1.cs
Created September 15, 2012 16:44
code snippets for "Automatically Including Current Language In Generated URLs With ASP.NET MVC" post
public class AutoLocalizingRoute : Route
{
public AutoLocalizingRoute(string url, object defaults, object constraints)
: base(url, new RouteValueDictionary(defaults), new RouteValueDictionary(constraints), new MvcRouteHandler()) { }
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
// only set the culture if it's not present in the values dictionary yet
// this check ensures that we can link to a specific language when we need to (fe: when picking your language)
if (!values.ContainsKey("language"))
@davybrion
davybrion / s1.js
Created September 15, 2012 16:41
code snippet for "Who Needs Classes Anyway?" post
var MyNameSpace = MyNameSpace || {};
MyNameSpace.jsondateformatter = (function () {
var that = this;
var toDate = function (jsonDateString) {
var time = jsonDateString.replace(/\/Date\(([0-9]*)\)\//, '$1');
var date = new Date();
date.setTime(time);
return date;
@davybrion
davybrion / s1.cs
Created September 15, 2012 16:36
code snippets for "Sharing An IE Instance Among Multiple Tests With WatiN And MS Test" post
public static class IEStaticInstanceHelper
{
// TODO: move this to a config file
public const string ROOT_URL = "http://localhost:13834/";
private static IE _ie;
private static int _previouslyKnownIeThreadHashCode;
private static string _ieHwnd;
public static void Initialize()
@davybrion
davybrion / s1.cs
Created September 15, 2012 16:29
code snippets for "Convention Based Localization With ASP.NET MVC" post
@Html.LabelFor(m => m.SomeProperty)
@davybrion
davybrion / s1.cs
Created September 15, 2012 16:26
code snippets for "Using Generic TestFixtures To Run Tests In Multiple Browsers With WatiN" post
public abstract class ViewTest<TBrowser> where TBrowser : Browser, new()
{
[TestFixtureSetUp]
public void FixtureSetUp()
{
Browser = new TBrowser();
Browser.GoTo(RootUrl);
}
[TestFixtureTearDown]
@davybrion
davybrion / s1.cs
Created September 15, 2012 16:12
code snippets for "Using Distributed Caching With Agatha" post
public class MembaseCache : ICache
{
private readonly MembaseClient membaseClient;
public MembaseCache(string region = null)
{
// this implementation assumes password-less buckets
membaseClient = new MembaseClient(region, null);
}
@davybrion
davybrion / s1.cs
Created September 15, 2012 16:08
code snippets for "Thou Shalt Name Thy Parameter “command”"
[GridAction(EnableCustomBinding = true)]
public ActionResult GetModels(GridCommand gridCommand)
@davybrion
davybrion / s1.cs
Created September 15, 2012 16:02
code snippets for "Prefixing Input Elements Of Partial Views With ASP.NET MVC" post
public class NameModel
{
[Display(Name = "First name")]
[Required]
public string FirstName { get; set; }
[Display(Name = "Last name")]
[Required]
public string LastName { get; set; }
}
@davybrion
davybrion / s1.rb
Created September 15, 2012 15:04
code snippets for "Why You Don’t Need Dependency Injection In Ruby" post
class Dependency
def do_something_with(some_object)
p some_object
end
end
class SomeClass
def work_your_magic_on(something)
Dependency.new.do_something_with something
end
@davybrion
davybrion / s1.rb
Created September 15, 2012 14:59
code snippets for "Writing A Simple DSL" post
require 'forwardable'
class Model
extend Forwardable
def initialize
@entities = []
end
def add_entity(entity)