Skip to content

Instantly share code, notes, and snippets.

@hartez
hartez / gist:3881051
Created October 12, 2012 19:35
Convertinator celcius
var celcius = new Unit("Celcius")
.IsAlsoCalled("celcius", "Centigrade", "centigrade", "degrees Celcius", "degrees Centigrade")
.IsAlsoCalled("celcuis") // typo from legacy system
.CanBeAbbreviated("°C")
.PluralizeAs("°C");
@hartez
hartez / gist:3881027
Created October 12, 2012 19:31
Convertinator more complex example
var graph = new ConversionGraph();
var meter = new Unit("meter");
var feet = new Unit("foot");
var kilometer = new Unit("kilometer");
var inches = new Unit("inch");
graph.AddConversion(
Conversions.From(kilometer).To(meter).MultiplyBy(1000M),
Conversions.From(meter).To(feet).MultiplyBy(3.28084M),
@hartez
hartez / convertinator_interfaces.cs
Created October 12, 2012 19:29
Convertinator Conversion interfaces
public interface IConversion
{
IEnumerable<IConversionStep> Steps { get; }
void AddStep(IConversionStep step);
Conversion Reverse();
}
public interface IConversionStep
{
decimal Apply(decimal input);
@hartez
hartez / gist:3880921
Created October 12, 2012 19:13
Convertinator basic example
var graph = new ConversionGraph();
var meter = new Unit("meter");
var feet = new Unit("foot");
graph.AddConversion(Conversions.One(meter).In(feet).Is(3.28084M));
@hartez
hartez / jquery-validation-engine_with_select2
Created June 25, 2012 22:27
Workaround for using jquery-validation-engine with select2 for 'required' validation
<script type="text/javascript">
// This is a workaround for using jquery-validation-engine with select2 for 'required' validation
// Since the _required validator for jquery-validation-engine uses .val() to see
// if there's anything in the input, we can hijack .val() for the container created by select2\
// and redirect it to the value of the hidden element
// jquery-validation-engine throws an error if the thing we're validating doesn't have an id
// so we'll put one on the container created by select2 (that way, the positioning of the prompts
// will be correct)
$('#mySelector').select2('container').attr('id', 'mySelectorValidate');
@hartez
hartez / gist:1335363
Created November 3, 2011 00:02
Ridiculous operator overloading with expressions trees
internal class Program
{
private static void Main(string[] args)
{
var x = new Number<int>(3);
var y = new Number<int>(-4);
Number<int> result = x + y; // result is 7
Console.WriteLine(result);