Skip to content

Instantly share code, notes, and snippets.

watch:
watchy -w css/**/*.less -- make css
grunt.initConfig({
watch: {
less: {
files: ['css/**/*.less'],
tasks: ['css']
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.initConfig({
less: {
src: ['styles.less'],
dest: 'styles.css'
},
postcss: {
options: {
processors: [
require('autoprefixer')(),
]
css:
lessc style.less | autoprefixer-cli > style.css
var Router = Backbone.Router.extend({
before: function() {
console.log('before');
},
after: function() {
console.log('after');
},
routes: {
// save a reference to route() method
var $route = Backbone.Router.prototype.route;
// then override it
Backbone.Router.prototype.before = function() {}
Backbone.Router.prototype.after = function() {}
Backbone.Router.prototype.route = function(route, name, callback) {
if (_.isFunction(name)) {
callback = name;
name = '';
var coll = new Backbone.Collection([model1, model2]);
console.log(coll.search('Jordan').first().get('last_name')); // Aslam
console.log(coll.search('John').first().get('last_name')); // Doe
console.log(coll.search(/Jo/).pluck('last_name')); // ['Aslam', 'Doe']
console.log(coll.search(/Jordan|John/).pluck('last_name')): // ['Aslam', 'Doe']
Backbone.Collection.prototype.search = function(test) {
return this.filter(function(model) {
return model.match(test);
});
}
var model1 = new Backbone.Model({ first_name: 'Jordan', last_name: 'Aslam' });
var model2 = new Backbone.Model({ first_name: 'John', last_name: 'Doe' });
console.log(model1.match(‘Jordan’)); // true
console.log(model2.match(‘Doe’)); // true
console.log(model1.match(/Jo/)); // true
console.log(model2.match(/Jo/)); // true
Backbone.Model.prototype.match = function(test) {
return _.any(this.attributes, function(attr) {
return _.isRegExp(test) ? test.test(attr) : attr == test;
});
}