Skip to content

Instantly share code, notes, and snippets.

View Jaecen's full-sized avatar

Jason Addington Jaecen

  • Procare Software
  • Oregon, USA
View GitHub Profile
BEGIN MESSAGE.
qJUPhAKDn0ZkEaK lAbgzP2Fs8mKLu8 HOyIQaX2DSEzAwW g8Xj3xE4Z7Fm7iP
zmSNH4A26GepjM7 5sP52SuItugTCKq 6Xr2MZHgg4bgTQ8 ohbXLCXqpOeMUJH
w7hgyOan0OEmeBN sL5n2on1uxU3pAd mGvB5lqKAx4r5D9 FF3xU0rDOKqps8J
akj1bjEKGIycf8Q CkfJ3TVneEXcLZn q5v0621.
END MESSAGE.
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace AesKeySizes
{
// This class holds our encryption and authentication keys. We use a class just to make it
// easier to pass these values around.
@Jaecen
Jaecen / AlwaysReturns.cs
Created February 22, 2017 00:53
Mocking HttpClient
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace DotUpgrade.Test
{
class AlwaysReturns : HttpMessageHandler
{
readonly HttpStatusCode StatusCode;
@Jaecen
Jaecen / SafeModelStateTempDataTransfer.cs
Created January 5, 2017 23:07
Improved filters for POST redirect GET model state transfer.
using System.Web.Mvc;
namespace AspDotNetStorefront.Filters
{
public class SafeExportModelStateToTempData : ActionFilterAttribute
{
public const string Key = "ExportedModelState";
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
@Jaecen
Jaecen / ModelStateDictionaryExtensions.cs
Created January 4, 2017 01:15
Maps ModelState values onto a property indicated by a lambda. Used to merge ModelStates from one model to another (i.e. PostModel to RenderModel). Usage: `ModelState.Apply(otherModel, m => m.SomeProperty)`
public static class ModelStateDictionaryExtensions
{
public static TValue Apply<TSource, TValue>(this ModelStateDictionary modelState, TSource source, Expression<Func<TSource, TValue>> selectorExpression)
{
// Extract property info from the selector expression
var memberExpression = selectorExpression.Body as MemberExpression;
if(memberExpression == null)
throw new ArgumentException($"Expression '{selectorExpression}' does not refer to a property", nameof(selectorExpression));
var propertyInfo = memberExpression.Member as PropertyInfo;

Keybase proof

I hereby claim:

  • I am Jaecen on github.
  • I am jaecen (https://keybase.io/jaecen) on keybase.
  • I have a public key whose fingerprint is BBB4 C8AC D27E 8FCE 314A 3231 4DF5 FAFD D710 E437

To claim this, I am signing this object:

@Jaecen
Jaecen / siren.cs
Created November 9, 2013 18:59
A simple C# implementation of Siren.
public class Siren
{
public readonly string Title;
public readonly IEnumerable<string> Class;
public readonly IDictionary<string, string> Properties;
public readonly IEnumerable<Entity> Entities;
public readonly IEnumerable<Action> Actions;
public Siren(
string title = null,