Skip to content

Instantly share code, notes, and snippets.

View mxmissile's full-sized avatar
🎯
Focusing

Travis mxmissile

🎯
Focusing
View GitHub Profile
@mxmissile
mxmissile / gist:d81682def1d88a522767
Created August 27, 2015 19:39
Fluent Nhibernate Specs
var addresses = new[] {new PostalAddress(), new PostalAddress()};
var spec = new PersistenceSpecification<Contact>(session);
spec.CheckProperty(p => p.Name, "something")
.CheckProperty(p => p.GivenName, "something else")
.CheckInverseList(l => l.Addresses, addresses)
etc etc
.VerifyTheMappings();
public class PostalAddressMap
: ClassMap<PostalAddress>
{
public PostalAddressMap()
{
Table("tblPostalAddresses");
Id(x => x.Id);
Map(x => x.Address);
Map(x => x.AddressType);
Map(x => x.Owner);
public class MyViewEngine : RazorViewEngine
{
/// <summary>
/// default ~/views
/// </summary>
/// <param name="startingPath"></param>
public MyViewEngine(string startingPath)
{
var formats = new[]
{
public class Impersonation : IDisposable
{
public Impersonation(string username, string password, string domain)
{
try
{
IntPtr tokenHandle; // = IntPtr.Zero;
Int32 ret;
if (
using (var imageFactory = new ImageFactory())
{
var layer = new ResizeLayer(new Size(800, 500), null, ResizeMode.Stretch);
imageFactory.Load(ms)
.Resize(layer)
.Format(ImageFormat.Jpeg)
.Quality(90)
.Save(path);
}
public class FubuRegistry : Registry
{
public FubuRegistry()
{
var htmlConventionLibrary
= new HtmlConventionLibrary();
var conventions
= new OverrideHtmlConventions();
htmlConventionLibrary.Import(conventions.Library);
For<HtmlConventionLibrary>().Use(htmlConventionLibrary);
@mxmissile
mxmissile / gist:6a59527890e4be3d9213
Created July 21, 2014 22:26
@Html.LabelWithInput(...)
public static HtmlTag LabelWithInput<T>(this HtmlHelper<T> helper, Expression<Func<T, object>> expression) where T : class
{
var generator = GetGenerator<T>();
var label = generator.LabelFor(expression, model: helper.ViewData.Model);
var input = generator.InputFor(expression, model: helper.ViewData.Model);
var div = new DivTag();
div.AddClass("form-group");
div.Append(label);
div.Append(input);
@mxmissile
mxmissile / gist:019294152da407ca52f1
Created September 3, 2014 20:55
Rewrite rule for IIS rewrites everything to https
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
courtesy of Sides of March
http://www.sidesofmarch.com/index.php/archive/2014/09/02/forcing-iis-to-rewrite-all-requests-to-https/
public object GetService(Type serviceType)
{
try
{
return container.Resolve(serviceType);
}
catch
{
return null;
}
@mxmissile
mxmissile / gist:826264
Created February 14, 2011 18:03
ActionButton
public static MvcHtmlString ActionButton<T>(this HtmlHelper helper, Expression<Action<T>> action, string text) where T : Controller
{
return ActionButton(helper, action, text, null);
}
public static MvcHtmlString ActionButton<T>(this HtmlHelper helper, Expression<Action<T>> action, string text, object htmlAttributes) where T : Controller
{
var routing = ExpressionHelper.GetRouteValuesFromExpression(action);
var vpd = helper.RouteCollection.GetVirtualPath(helper.ViewContext.RequestContext, routing);