Skip to content

Instantly share code, notes, and snippets.

View rdingwall's full-sized avatar

Richard Dingwall rdingwall

View GitHub Profile
@rdingwall
rdingwall / RavenUniqueInserter.cs
Created March 1, 2012 16:22
Raven DB unique constraint inserter
public interface IRavenUniqueInserter
{
void StoreUnique<T, TUnique>(
IDocumentSession session, T entity,
Expression<Func<T, TUnique>> keyProperty);
}
public class RavenUniqueInserter : IRavenUniqueInserter
{
public void StoreUnique<T, TUnique>(IDocumentSession session, T entity,
@rdingwall
rdingwall / ExampleController.cs
Created March 9, 2012 12:27
RavenDB ASP.NET Web API session management
public class BooksApiController : FooApiController
{
public IEnumerable<Book> Get()
{
return DocumentSession
.Query<Book>()
.OrderByAscending(p => p.Author)
.Take(100);
}
}
@rdingwall
rdingwall / Global.asax.cs
Created March 10, 2012 19:39
camelCase + indented JSON formatter for ASP.NET Web API
...
var config = GlobalConfiguration.Configuration;
// Replace the default JsonFormatter with our custom one
var index = config.Formatters.IndexOf(config.Formatters.JsonFormatter);
config.Formatters[index] = new JsonCamelCaseFormatter();
...
@rdingwall
rdingwall / FilterIPAttribute.cs
Created March 13, 2012 13:45
FilterIPAttribute for ASP.NET Web API (IIS only, port of MVC version from http://stackoverflow.com/a/4605086/91551)
using System;
using System.Configuration;
using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;
namespace Miscellaneous.Attributes.Controller
{
/// <summary>
/// Filter by IP address (ASP.NET Web API version)
@rdingwall
rdingwall / mocha-tc.html
Created April 29, 2012 20:33
Mocha.js TeamCity reporter async bug
<!DOCTYPE html>
<html>
<head>
<!-- Mocha 1.0.2 at time of writing -->
<script type="text/javascript" src="https://raw.github.com/visionmedia/mocha/master/mocha.js"></script>
<link rel="stylesheet" type="text/css" href="https://raw.github.com/visionmedia/mocha/master/mocha.css" />
</head>
<script lang="text/javascript">
mocha.setup({
ui: "bdd",
@rdingwall
rdingwall / teamcity_reporter.html
Created June 17, 2012 19:15
Jasmine PhantomJS event based exit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Console Reporter Spec</title>
<link rel="stylesheet" href="../ext/jasmine.css" type="text/css" />
<script type="text/javascript" src="../ext/jasmine.js"></script>
<script type="text/javascript" src="../ext/jasmine-html.js"></script>
@rdingwall
rdingwall / StripAuthorXMLComments.ps1
Created June 19, 2012 09:25
PowerShell script to strip <author> tags from C# files
# Powershell to recursively strip all <author> XML comments out of *.cs files.
# See 'collective code ownership' for why we do not want to encourage individual
# developers claiming/marking sections of code
# http://jamesshore.com/Agile-Book/collective_code_ownership.html.
#
# (And if for some reason you really want to know who worked on a class, SVN
# blame will give you a MUCH better picture anyway).
dir -recurse -filter *.cs $src | foreach ($_) {
$file = $_.fullname
echo $file
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using CsvHelper.Configuration;
using Xunit;
namespace CsvHelper.Tests
{
@rdingwall
rdingwall / StandaloneSeqHiloGenerator.cs
Created September 19, 2012 10:07
StandaloneSeqHiloGenerator - ported from NHibernate
using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlTypes;
using System.Runtime.CompilerServices;
using Oracle.DataAccess.Client;
namespace Foo
{
/// <summary>
@rdingwall
rdingwall / lessjs.rb
Last active August 29, 2015 14:07 — forked from andyfowler/lessjs.rb
Modified lessjs.rb to process included dependencies in the correct order, starting from main.less
module Jekyll
class LessCssFile < StaticFile
def write(dest)
# do nothing
end
end
# Expects a lessc: key in your _config.yml file with the path to a local less.js/bin/lessc
# Less.js will require node.js to be installed