Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Linq;
using System.Data.Entity;
namespace TestEF
{
public class Thing
{
public int Id {
get;
public class OwershipVerification : IActionFilter
{
public void OnActionExecuting(ActionExecutingContext filterContext)
{
foreach(var paramter in filterContext.ActionParameters)
{
var haveAnOwner = paramter.Value as IHaveAnOwner;
if(haveAnOwner != null)
{
var ownedParameter = haveAnOwner;
public class FlexRoleUserStore<TContext, TRole, TUser> : IFlexRoleDataStore
where TRole : class, IFlexRole<TUser>, new()
where TUser : IFlexMembershipUser
where TContext : DbContext
{
// ...
}
@OdeToCode
OdeToCode / gist:5024867
Last active December 14, 2015 03:59
AngularJS Snippet
<div ng-app="videoApp" ng-controller="VideoController">
<table>
<thead>
<th>Title</th>
<th>Length</th>
<th></th>
</thead>
<tbody>
<tr data-id="{{video.Id}}" ng-repeat="video in videos">
@OdeToCode
OdeToCode / gist:7538117
Created November 19, 2013 00:40
Restrict OWIN CORS to Token endpoint.
app.UseCors(new CorsOptions()
{
PolicyProvider = new CorsPolicyProvider()
{
PolicyResolver = request =>
{
if (request.Path.StartsWithSegments(new PathString("/token")))
{
return Task.FromResult(new CorsPolicy { AllowAnyOrigin = true });
}
let PeriodValue payment rate period =
payment / ((1.0 + rate) ** period)
let PresentValue (factors: AnnuityFactors) =
[1 .. factors.Periods]
|> List.map (fun period -> PeriodValue factors.Payment factors.InterestRate (float period))
|> List.sum
public UserManager()
: base(new UserStore<ApplicationUser>(new ApplicationDbContext()))
{
UserValidator = new UserValidator<ApplicationUser>(this) { AllowOnlyAlphanumericUserNames = false };
}
@OdeToCode
OdeToCode / gist:e43279d671b7930018a4
Created May 13, 2014 12:26
Subscribe and unsubscribe from events
public class Worker
{
public void StartWork()
{
for (var i = 0; i < 10; i++)
{
OnInterestingEvent();
Thread.Sleep(1000);
}
OnComplete();
<Window x:Class="WpfApplication8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
<!-- event wire up here: -->
Loaded="MainWindow_Loaded">
<Canvas x:Name="DrawingCanvas">
</Canvas>
public class Logger(Stream stream) : IDisposable
{
public void Dispose()
{
Stream.Dispose();
}
public Stream Stream { get; set; } = stream;
}