Skip to content

Instantly share code, notes, and snippets.

View roryf's full-sized avatar

Rory Fitzpatrick roryf

  • Edinburgh, Scotland
View GitHub Profile
@roryf
roryf / IndexlessEnumerableModelBinder.cs
Created March 29, 2012 16:09
An ASP.NET MVC ModelBinder for binding form values of the form name[].property rather than name[index].property. Assumes form values are POSTed in markup order, unsure if this is always true.
public class IndexlessEnumerableModelBinder<TItemType> : DefaultModelBinder
where TItemType : class
{
protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)
{
if (typeof(IEnumerable<TItemType>).IsAssignableFrom(propertyDescriptor.PropertyType))
{
var nameOfPropertyToBind = propertyDescriptor.Name;
var form = controllerContext.HttpContext.Request.Form;
@roryf
roryf / wireframe.mrules
Created September 9, 2011 12:50
Maperitive rules for creating white-on-black maps of primary roads
// Wireframe rules
// Created by Igor Brejc
// Edited by Rory Fitzpatrick
// Released under the Creative Commons Attribution-ShareAlike 3.0 License (http://creativecommons.org/licenses/by-sa/3.0/)
features
lines
line : highway=primary OR highway=tertiary OR highway=motorway OR highway=trunk OR highway=secondary
coastline : natural=coastline
@roryf
roryf / DeliminatorSeparatedPropertyNamesContractResolver.cs
Created June 23, 2011 13:09
Snake case (underscore separated) property name resolver for Newtonsoft.Json library
public class DeliminatorSeparatedPropertyNamesContractResolver : DefaultContractResolver
{
private readonly string _separator;
protected DeliminatorSeparatedPropertyNamesContractResolver(char separator) : base(true)
{
_separator = separator.ToString();
}
protected override string ResolvePropertyName(string propertyName)
@roryf
roryf / movie.pde
Created September 9, 2011 12:39
Processing code I used to generate http://vimeo.com/28706322
import org.json.*;
import java.net.*;
import java.util.Iterator;
import processing.video.*;
PImage bg;
MovieMaker mm;
JSONObject data;
double west = -3.414001;
@roryf
roryf / controller_decorator.js
Created December 11, 2013 10:29
Proof of concept to allow ui-router resolvers to also apply when controllers are created via ng-controller directive.
angular.module('ui.router').config(['$provide', function($provide) {
$provide.decorator('$controller', [
'$delegate', '$state',
function($delegate, $state) {
return function(expression, locals) {
if ($state.$current) {
locals = _.extend(locals, $state.$current.locals.globals);
}
return $delegate(expression, locals);
@roryf
roryf / this.js
Created November 20, 2013 00:20
Pop quiz
var one = {
name: 'one',
hello: function() {
console.log(this.name);
}
};
var two = {
name: 'two'
};
@roryf
roryf / Example.cs
Created February 13, 2013 12:47
Object extension method to peek at a private field. Useful when testing an against an object which has state but will not actually execute anything. See example using NSubstitute.
repository.Query(Arg.Is<FindUserByEmailQuery>(x => x.PeekPrivateField("emailAddress") == "foo@bar.com")).Returns(user);
@roryf
roryf / tabs.html
Created December 4, 2012 11:21
Better tabs
<div class="responsive-tabs">
<section class="tab-panel">
<h2 class="tab-anchor">Item 1</h2>
<div class="tab-content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tincidunt pellentesque lorem, id suscipit dolor rutrum id. Morbi facilisis porta volutpat. Fusce adipiscing, mauris quis congue tincidunt, sapien purus suscipit odio, quis dictum odio tortor in sem. Ut sit amet libero nec orci mattis fringilla. Praesent eu ipsum in sapien tincidunt molestie sed ut magna. Nam accumsan dui at orci rhoncus pharetra tincidunt elit ullamcorper. Sed ac mauris ipsum. Nullam imperdiet sapien id purus pretium id aliquam mi ullamcorper.</p>
</div>
</section>
<section class="tab-panel">
@roryf
roryf / .gitignore
Created July 5, 2012 14:08
.gitignore for working with Visual Studio
build/
release/
package/
*.suo
*.user
bin
!/bin
obj
_ReSharper*
*.csproj.user
@roryf
roryf / gist:2214167
Created March 27, 2012 09:00
Umbraco SQL query for AncestorContentOrSelf
SELECT this_.Id as Id16_9_,
this_.DateCreated as DateCrea2_16_9_,
this_.DefaultName as DefaultN3_16_9_,
this_.AttributeSchemaDefinition_id as Attribut4_16_9_,
this_.NodeId as NodeId16_9_,
attribalia3_.NodeVersionId as NodeVers3_11_,
attribalia3_.Id as Id11_,
attribalia3_.Id as Id5_0_,
attribalia3_.AttributeDefinitionId as Attribut2_5_0_,
attribalia3_.NodeVersionId as NodeVers3_5_0_,