Skip to content

Instantly share code, notes, and snippets.

View jamescrowley's full-sized avatar

James Crowley jamescrowley

View GitHub Profile
@ashtonkj
ashtonkj / CustomModelBinder.fs
Created September 9, 2014 13:59
WebApi Default Args Binder
type CustomBinder() =
interface IModelBinder with
member this.BindModel(actionContext:HttpActionContext, bindingContext :ModelBindingContext) =
let qs = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query)
bindingContext.Model <-
if (qs.AllKeys |> Seq.exists(fun q -> q.ToLower() = bindingContext.ModelName.ToLower())) then
qs.[bindingContext.ModelName] |> Some
else
None
true
// Experimental stuff until we get a better picture of how to approach page tree, levels, subpages and such
public class MenuBuilder : IMenuBuilder
{
private readonly IPages _pages;
private readonly IContextualMenu<Page> _pagesMenu;
private readonly Page _currentPage;
public MenuBuilder(IPages pages, IContextualMenu<Page> pagesMenu, Page currentPage)
{
@CoreyKaylor
CoreyKaylor / ModelUrlResolutionCache.cs
Created January 5, 2012 02:36
Transforms InputModel for FubuMVC into the route for asset files, this makes routes refactor friendly and safe from route changes
public class ModelUrlResolutionCache : IModelUrlResolver
{
static Cache<string, string> _inputModelTypeCache;
public ModelUrlResolutionCache(IUrlRegistry urlRegistry, BehaviorGraph graph)
{
if (_inputModelTypeCache == null)
_inputModelTypeCache = new Cache<string, string>(inputModel =>
{
var inputType = Type.GetType(inputModel)
@model EditUserModel
@using (Html.BeginForm())
{
<div>
@Html.HiddenFor(m => m.Id)
@Html.TextBoxFor(m => m.FirstName)
@Html.TextBoxFor(m => m.LastName)
@Html.DropDownListFor(m => m.CountryId, Model.Countries)
@mikeobrien
mikeobrien / DownloadDataBehavior.cs
Created April 20, 2012 17:09
Download data convention
public class DownloadDataModel
{
public string Data { get; set; }
public string Filename { get; set; }
public string MimeType { get; set; }
}
public class DownloadDataBehavior : BasicBehavior
{
private readonly IFubuRequest _request;
@pagebrooks
pagebrooks / JsonNetResult.cs
Created December 7, 2012 00:28
Angular Compatible Date Formatting with JSON.NET
public class JsonNetResult : JsonResult
{
private readonly static JsonSerializerSettings Settings;
private readonly static IsoDateTimeConverter _dateTimeConverter;
static JsonNetResult()
{
_dateTimeConverter = new IsoDateTimeConverter();
// Default for IsoDateTimeConverter is yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK
_dateTimeConverter.DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFK";
@mbenford
mbenford / Bootstrap.bat
Created May 27, 2013 19:09
Bootstrap script to register a Tentacle with an Octopus server and deploy a release to its environment/role. Requires a Tentacle installer and Octo.exe in the same directory of the script.
start /wait msiexec /i Octopus.Tentacle.<version>.msi /quiet INSTALLLOCATION=C:\Octopus
cd C:\Octopus\Agent
tentacle configure --appdir="C:\Applications" --port=10933 --trust=<server-thumbprint>
tentacle new-certificate
tentacle install
tentacle register-with --server=<server-url> --environment=<environment> --role=<role> --apikey=<some-user-apikey>
octo deploy-release --project=<project-name> --deployto=<environment-to-deploy> --version=<version-to-deploy> --server=<server-url> --apikey=<some-user-apikey>
@mattwarren
mattwarren / gist:1214297
Created September 13, 2011 16:53
Faceted search SO example
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using Raven.Abstractions.Data;
using Raven.Abstractions.Indexing;
using Raven.Client;
using Raven.Client.Linq;
@PaulStovell
PaulStovell / Group.cs
Created March 31, 2012 11:15
Hierarchies in RavenDB
public class Group
{
public Group()
{
Users = new List<string>();
ChildGroups = new List<string>();
}
public string Id { get; set; }
public string Name { get; set; }
@joefitzgerald
joefitzgerald / Vagrantfile
Last active July 6, 2018 12:33
Windows Vagrantfile - Installs .NET 4.5, VS 2012, VS 2012 Update 3, then a bunch of utilities, then syspreps the machine. Get https://github.com/joefitzgerald/packer-windows for the base box and add it with the name "windows2008r2".
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "vagrant-windows"
config.vm.box = "windows2008r2"
# You should be using the vagrant-windows Vagrant Plugin!
# Admin user name and password
config.winrm.username = "Administrator"