Skip to content

Instantly share code, notes, and snippets.

View hartez's full-sized avatar

E.Z. Hart hartez

View GitHub Profile
@hartez
hartez / AddressController.cs
Created June 23, 2014 18:07
Controller without documentation
public class AddressController : ApiController
{
public IEnumerable<AddressViewModel> Get()
{
return Addresses.Get();
}
[Route(Name = "GetAddress")]
public AddressViewModel Get(int id)
{
@hartez
hartez / AddressController.cs
Created June 23, 2014 18:13
Address controller with comments
/// <summary>
/// Endpoints for managing Addresses
/// </summary>
public class AddressController : ApiController
{
/// <summary>
/// Gets a list of addresses in the system
/// </summary>
/// <returns>IEnumerable&lt;AddressViewModel&gt;.</returns>
public IEnumerable<AddressViewModel> Get()
@hartez
hartez / RefactorableSettingsTemplate.tt
Created August 15, 2014 23:36
T4 template for generating refactorable settings
<#@ template language="C#" hostspecific="True" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Xml" #>
<#
XmlDocument doc = new XmlDocument();
doc.Load(Path.Combine(Path.GetDirectoryName(Host.TemplateFile), "Settings.settings"));
string xmlns = doc.DocumentElement.Attributes["xmlns"].Value;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
@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);
@hartez
hartez / attachments3.py
Created October 4, 2015 19:21
Plotting email attachment data using pandas
import pandas as pd
import numpy as np
import humanfriendly
import matplotlib.pyplot as plt
plt.style.use('ggplot')
import os.path
# Read in our email data file
df = pd.read_csv('../attachments2.csv', header = 0)
@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 / 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 / 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: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:3881054
Created October 12, 2012 19:35
Convertinator temperature
var temperature = new ConversionGraph();
var fahrenheit = new Unit("degrees Fahrenheit")
.IsAlsoCalled("Fahrenheit")
.CanBeAbbreviated("°F")
.PluralizeAs("°F");
temperature.AddConversion(
Conversions.From(fahrenheit).To(celcius).Subtract(32).MultiplyBy(5M / 9M));