This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValidateChildAttribute : ValidationAttribute { | |
public override bool IsValid(object value) { | |
if (value == null) return true; | |
var isValid = IsItValid(value); | |
if (!isValid) return false; | |
if (value is IEnumerable) return ((IEnumerable)value).Cast<object>().All(IsItValid); | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(jQuery) { | |
jQuery.fn.validator = function(options) { | |
var isEmpty = function(obj) { return obj == null || obj.length == 0; }; | |
var opts = jQuery.extend(true, { // Allows for overriding any messages or validator functions | |
wrapperClass: "invalid", messageClass: "message", useMessages: true, | |
onValidation: null, onValidationFailed: null, // Callbacks which recieve an object containing the element and state { el: el, state: state } | |
validateOn: "blur", // The jQuery events that cause validation to occur |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Backbone.Model.prototype.save = (function(original) { | |
return function(attrs, options) { | |
var me = this; | |
options = options || {}; | |
var origSuccess = options.success; | |
var wasNew = this.isNew(); | |
options.success = function(model, response) { | |
if (me.collection && !wasNew) { me.collection.trigger("update", me); } | |
if (origSuccess) { origSuccess(model, response); } | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Backbone.View.prototype.proxy = function(source, eventName, options) { | |
if (!options) { options = {}; } | |
var self = this; | |
source.bind(eventName, function(args) { | |
var name = options["proxyName"] || eventName; | |
var newArgs = options["proxyArgs"] ? _.combine(args, options["proxyArgs"]) : args; | |
self.trigger(name, newArgs); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Metadata - jQuery plugin for parsing metadata from elements | |
* | |
* Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan | |
* | |
* Dual licensed under the MIT and GPL licenses: | |
* http://www.opensource.org/licenses/mit-license.php | |
* http://www.gnu.org/licenses/gpl.html | |
* | |
* Revision: $Id: jquery.metadata.js 3640 2007-10-11 18:34:38Z pmclanahan $ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mongoid | |
module NumericIdentity | |
module InstanceMethods | |
def generate_identity | |
id_attempt = (self.class.last.try(:id) || 0) + 1 | |
dup_check = self.class.where(:id => id_attempt).first | |
if dup_check.nil? | |
self.id = id_attempt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :deploy => ['deploy:push', 'deploy:restart', 'deploy:tag'] | |
namespace :deploy do | |
task :migrations => [:push, :off, :migrate, :restart, :on, :tag] | |
task :rollback => [:off, :push_previous, :restart, :on] | |
task :push do | |
puts 'Deploying site to Heroku ...' | |
puts `git push heroku` | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
module Kernel | |
alias old_require require | |
def require(path) | |
output = nil | |
@required_files ||= [] | |
benchmark = Benchmark.measure do | |
output = old_require path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product < ActiveRecord::Base | |
def self.find_by_criteria(params) | |
query = where("id IS NOT null") # A little odd but not sure how to get an ActiveRecord::Relation that returns "all" | |
query = query.where("price = ?", params[:price]) if params[:price].present? | |
query = query.where("manufacturer = ?", params[:manufacturer]) if params[:manufacturer].present? | |
query = query.where("retailer = ?", params[:retailer]) if params[:retailer].present? | |
query = query.where("category = ?", params[:category]) if params[:category].present? | |
query | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include ActiveSupport | |
["app/**/", "lib/**/"].each do |glob| | |
Dir.glob(glob).each do |dir| | |
Dependencies.autoload_paths << File.join(File.dirname(__FILE__), dir) | |
end | |
end |
OlderNewer