Skip to content

Instantly share code, notes, and snippets.

View ajsharp's full-sized avatar

Alex Sharp ajsharp

View GitHub Profile
@ajsharp
ajsharp / gist:3025465
Created June 30, 2012 20:52
backbone 0.9.2 Model validations -- both set and save call _validate
_validate: function(attrs, options) {
if (options.silent || !this.validate) return true;
attrs = _.extend({}, this.attributes, attrs);
var error = this.validate(attrs, options);
if (!error) return true;
if (options && options.error) {
options.error(this, error, options);
} else {
this.trigger('error', this, error, options);
}
class SomeProtocol
class NotImplementedError < StandardError
end
def implement_me
raise NotImplementedError
end
end
class SomeBackgroundJob
@queue = :whatever
def self.perform(model_id)
model = Model.find(model_id)
model.do_a_thing
end
end
Zaarly.NativeEventRouter = function() {
return {
'ok.click' : 'nagivate.editProfile',
'exit.click' : 'webview.close'
}
}
object :user do
object :profile do
object :nested do
attributes :property
end
end
end
class SomeMiddleware
HOSTNAME = `hostname`.chomp.freeze
def initialize(app)
@app = app
end
def call(env)
if HOSTNAME == 'app1'
status, headers, body = @app.call(env)
# This class is responsible API parameter type coercion and defaults.
class ListingSearchParam
APPROVED = [:query, :latlng, :box, :sort, :limit, :page, :category_ids, :fulfilled]
def self.parse(opts = {})
new(opts).parse
end
def initialize(opts = {})
@errors = ActiveModel::Errors.new(self)
#!bash
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
users = _.map(users, function (i) { {i['month']: i['count']} }) // Uncaught SyntaxError: Unexpected token :
(defn count-reduce
[memo obj]
(let [key (str (year obj) "/" (month obj))]
(if (get memo key)
(merge memo {key (inc (get memo key))})
(merge memo {key 1}))))
(str
(reduce count-reduce {}
(map coerce-date