Skip to content

Instantly share code, notes, and snippets.

View tuespetre's full-sized avatar
😶

Derek Gray tuespetre

😶
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.WebPages;
public static class IsomorphicRazorExtensions
{
public static HelperResult Foreach<T>(this HtmlHelper helper, IEnumerable<T> items, Func<T, HelperResult> template)
where T : class, new()
@tuespetre
tuespetre / VersionedStaticFileHelper.cs
Last active August 29, 2015 14:22
An MVC helper class for adding hashes to versioned files (css, js, images, etc.)
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace Your.Project.Helpers
{
@tuespetre
tuespetre / FilterHelper.cs
Last active June 29, 2017 08:06
A utility class and general pattern for creating Github Issues-style Elasticsearch query string builder UIs.
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace Your.Web.Project
{
public static class FilterHelper
{
public static bool HasOption(string query, string option)
{
var regex = GetRegex(option);
@tuespetre
tuespetre / MultipartFormDataValueProvider.cs
Last active August 29, 2015 14:19
For use with pre-MVC6 Web API controllers
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.ValueProviders;
public class MultipartFormDataValueProvider : IValueProvider
{
@tuespetre
tuespetre / gist:f333b6bba4f9a8b496bc
Created October 11, 2014 15:17
Postal.Mvc5 HttpContext workaround (issue #73)
// Workaround for Postal.MVC5 1.2.0 issue 73
// https://github.com/andrewdavey/postal/issues/73
if (HttpContext.Current == null)
{
var baseURL = ConfigurationManager.AppSettings["baseURL"].TrimEnd('/');
var absolute = VirtualPathUtility.ToAbsolute("~/").TrimStart('/');
HttpContext.Current = new HttpContext(
new HttpRequest("", baseURL + "/" + absolute, ""),
new HttpResponse(new StringWriter())