Skip to content

Instantly share code, notes, and snippets.

View michaeljacobdavis's full-sized avatar

Mike Davis michaeljacobdavis

View GitHub Profile
@michaeljacobdavis
michaeljacobdavis / Helper.cs
Created July 27, 2012 15:55
Unit testing methods for nested Fluent Validation properties
// Adapted from http://devio.wordpress.com/2011/01/21/get-name-of-nested-property-as-string-value/
public static string GetPropertyName<T, TValue>(this T model, Expression<Func<T, TValue>> expression) where T : class
{
var memberExpression = (MemberExpression)expression.Body;
var memberExpressionOrg = memberExpression;
var Path = "";
while (memberExpression != null && memberExpression.Expression.NodeType == ExpressionType.MemberAccess)
@michaeljacobdavis
michaeljacobdavis / Site.css
Created July 27, 2012 18:23
Adding groups (1 message for multiple properties) to MVC3's Validation
.input-validation-error
{
border: 1px solid #ff0000;
background-color: #ffeeee;
}
span.input-validation-error {
border: none;
}
@michaeljacobdavis
michaeljacobdavis / Adapter.js
Created August 7, 2012 05:19
NotEqual Fluent Validation validator with client side validation
(function ($) {
$.validator.addMethod("notequal", function (value, element, param) {
return this.optional(element) || value != $(param).val();
}, "This has to be different...");
$.validator.unobtrusive.adapters.add("notequal", ["field"], function (options) {
options.rules["notequal"] = options.params.field;
if (options.message) options.messages["notequal"] = options.message;
});
})(jQuery);
(function ($) {
$.fn.formatfilename = function (options) {
var settings = $.extend({
'length': '40'
}, options);
return this.each(function () {
var $this = $(this);
$.fn.autotab = function () {
var inputEvents = "input";
if (!("oninput" in document || "oninput" in $("<input>")[0])) {
inputEvents += " keypress";
}
return this.each(function () {
var $this = $(this);
$this.on(inputEvents, "input[maxlength]", function (e) {
var $this = $(this);
if ($this.attr("maxlength") <= $(this).val().length) {
@michaeljacobdavis
michaeljacobdavis / inheritsFrom.js
Created December 13, 2012 00:33
inheritsFrom
Function.prototype.inheritsFrom = function (base) {
this.prototype = Object.create(base.prototype);
this.prototype.constructor = this;
this.prototype._super = base.prototype;
return this;
};
var Base = function () {
if (!(this instanceof Base))
throw ('Constructor called without "new"');
@michaeljacobdavis
michaeljacobdavis / Post-build event
Created February 9, 2013 06:20
R.js Minification on TFS build and Publish
cd "$(ProjectDir)Scripts"
node.exe r.js -o build.js
function sortBy(sequence, sorters) {
return sequence.slice().sort(function (a, b) {
var comparison = 0;
for (var i = 0; i < sorters.length; ++i) {
comparison = sorters[i](a, b);
if (comparison !== 0) {
return comparison;
}
}
return comparison;
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="http://localtodos.com/todos.css" />
</head>
<body>
function($http, $q) {
var cache = {};
return {
get: function (force){
var deferred = $q.defer();
if(force || !cache['get']){
return $http.get('/path/to/data').then(function(result){