Skip to content

Instantly share code, notes, and snippets.

@benfoster
benfoster / gist:5933185
Created July 5, 2013 09:13
Handling modelstate errors when hijaxing a form
$(".hijax").submit(function (e) {
var $form = $(this),
validator = $form.data("validator");
if (!$form.valid()) {
return;
};
$.ajax({
url: this.action,
@benfoster
benfoster / gist:5559456
Created May 11, 2013 09:42
NSpec Parameterised Specs?
void heading1_tag()
{
before = () => html = "<h1></h1>";
it["adds a paragraph with style 'Heading1'"] = ()
=> pdf.LastParagraph.Style.should_be("Heading1");
}
void heading2_tag()
{
before = () => html = "<h2></h2>";
@benfoster
benfoster / gist:5429305
Created April 21, 2013 11:29
Copying blobs between Azure Storage Accounts
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Threading;
namespace Utils.Migrations
{
public class BlobCopy
{
private readonly CloudStorageAccount sourceAccount;
namespace Fabrik.Common.Net
{
/// <summary>
/// RFC5988 Link relation types <see cref="http://www.iana.org/assignments/link-relations/link-relations.xml"/>.
/// </summary>
public static class LinkRelations
{
/// <summary>
/// Refers to a resource that is the subject of the link's context.
@benfoster
benfoster / gist:4701773
Last active December 12, 2015 02:48
ApiError class for Fabrik API
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net;
using System.Web.Http;
using System.Web.Http.ModelBinding;
namespace Fabrik.CMS.API.Client
{
[Serializable]
@benfoster
benfoster / gist:4577974
Created January 20, 2013 11:16
Hypermedia links that meet the JSON HAL specification. http://tools.ietf.org/html/draft-kelly-json-hal-03
{
"_links": {
"self": [
{
"href": "/orders/10"
}
],
"warehouse": [
{
"href": "/warehouse/10"
@benfoster
benfoster / gist:4488755
Created January 8, 2013 22:48
Patching in ASP.NET Web API
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
@benfoster
benfoster / gist:4474833
Last active December 10, 2015 18:29
Inbound Route Tests using ASP.NET Web API
[TestFixture]
public class InboundRouteTests
{
private Uri baseUri;
private HttpConfiguration config;
[TestFixtureSetUp]
public void FixtureSetUp()
{
baseUri = new Uri("https://tests.local");
@benfoster
benfoster / gist:4474276
Created January 7, 2013 11:08
Inbound route testing with ASP.NET MVC
using NSubstitute;
using NUnit.Framework;
using System.Linq;
using System.Web;
using System.Web.Routing;
namespace Fabrik.Web.Hosted.Specs
{
[TestFixture]
public class InboundRouteTests
@benfoster
benfoster / gist:4416655
Last active June 19, 2021 18:32
A lightweight message bus using TPL DataFlow
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
namespace TDFDemo
{
class Program
{