Skip to content

Instantly share code, notes, and snippets.

@troufster
troufster / generator.cs
Created May 18, 2011 10:47
Allow resharper to skip EF generated files
void BeginNamespace(string namespaceName, CodeGenerationTools code)
{
CodeRegion region = new CodeRegion(this);
if (!String.IsNullOrEmpty(namespaceName))
{
#>
#region EF Generated Code //<- right here
namespace <#=code.EscapeNamespace(namespaceName)#>
{
<#+
@troufster
troufster / beginform.cs
Created April 28, 2011 14:34
MVC3 Ajax Validation
@using (Html.BeginForm("Create", "MyModel", FormMethod.Post, new { id = "CreateForm" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>MyModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Property)
</div>
<div class="editor-field">
@troufster
troufster / AjaxStuff.cshtml
Created April 27, 2011 14:45
"Proper" handling of MVC3 Ajax links
@Html.ActionLink("Click me!", "AjaxStuff", null,
new { id = "ajaxstuff" })
@troufster
troufster / efcontext.cs
Created April 15, 2011 08:08
DbContext abstraction
using System;
using System.Data.Entity;
using Hurf.Durf.Model;
using System.Data;
namespace Derp.Model.UnitOfWork
{
/// <summary>
@troufster
troufster / ServiceLocator.cs
Created April 11, 2011 15:10
A simple service locator written for a project where "external" frameworks were not allowed :P
/// <summary>
/// A simple service locator implementation
/// </summary>
public class ServiceLocator : IServiceLocator
{
//A List of the registered services
private IDictionary<object, object> _services;
public ServiceLocator() {
_services = new Dictionary<object, object>();
public class InMemoryDbSet<T> : IDbSet<T> where T : class
{
readonly HashSet<T> _set;
readonly IQueryable<T> _queryableSet;
public InMemoryDbSet() : this(Enumerable.Empty<T>()) { }
public InMemoryDbSet(IEnumerable<T> entities) {
@troufster
troufster / dst.js
Created March 10, 2011 12:11
Detecting EU DST
function dstBounds(date, month) {
var d = new Date(date.getFullYear(),/*March*/(month-1),31),
day = d.getDay();
if (day != 0) d.setDate(d.getDate()-day);
//Dst starts @(UTC 01:00)
//this implementation is in UTC+1 (02:00)
d.setHours(2);
@troufster
troufster / Repository.cs
Created March 8, 2011 07:39
Generic repository for Entity Framework CTP5
interface IRepository<T> where T : class
{
void Add(T o);
void Commit();
System.Linq.IQueryable<T> Get();
void Remove(T o);
}
@troufster
troufster / Extrapolator.js
Created February 13, 2011 17:24
Cubic extrapolator
/*
* A cubic extrapolator using the polynomial
* P(T) = aT^2 + bT + c
*/
function Extrapolator() {
this.s = [];
this.t = [];
this.sol = [];
};
@troufster
troufster / interpolator.js
Created February 8, 2011 21:26
Simple 2d-vector interpolator
function Interpolator(type) {
this._i = type.func;
this._snum = type.samples;
this.s = []; //Samples
};
Interpolator.prototype.addSample = function(sample){
var p = this.s;
p.push(sample);
if(p.length > this._snum) p.shift();