Skip to content

Instantly share code, notes, and snippets.

View tgriesser's full-sized avatar

Tim Griesser tgriesser

View GitHub Profile
@tgriesser
tgriesser / bootstrap_buttons.less
Created February 1, 2012 18:55
A Less Implementation of the Bootstrap Buttons Generator
.customButton(@cHue: 201, @cSaturation: 1, @cLightness: .4, @cDelta: .1, @cMultiplier: 1.5) {
.cTextColor(@a, @b) when (@a < .5) { color: #fff; .cAlphaShadow(0, -1, 1, 0, (@b * 3.3)); }
.cTextColor(@a, @b) when (@a > .5) { color: #333; .cAlphaShadow(0, 1, 1, 255, (@b * 3.3)); }
.cTextColor(@a) { -webkit-font-smoothing: antialiased; }
.cAlphaShadow(@a, @b, @c, @d, @e) when (@e > 1) { text-shadow: (0px + @a) (0px + @b) (0px + @c) rgba(@d, @d, @d, 1); }
.cAlphaShadow(@a, @b, @c, @d, @e) when (@e < 1) { text-shadow: (0px + @a) (0px + @b) (0px + @c) rgba(@d, @d, @d, @e); }
@cHighlight: percentage(@cLightness + @cDelta);
@cLowlight: percentage(@cLightness - @cDelta);
@cSuperLowLight: percentage(@cLightness - @cDelta * @cMultiplier);
@tgriesser
tgriesser / gist:3188993
Created July 27, 2012 16:27 — forked from alappe/gist:3143376
No events…
namespace 'TimeLog.View', (exports) ->
class exports.Log extends Backbone.View
tagName: 'li'
events:
'click .date': 'lala'
template = _.template("""
@tgriesser
tgriesser / gist:3363709
Created August 15, 2012 21:11
backbone issue
test("multiple nested changes with silent2", 4, function() {
var changes = [];
var changesa = [];
var model = new Backbone.Model();
model.on('change:b', function(model, val) { changes.push(val); });
model.on('change:a', function(model, val) { changesa.push(val); });
model.on('change', function() {
model.set({b:3}, {silent:true});
model.set({a:3}, {silent:true});
model.set({a:1}, {silent:true});
@tgriesser
tgriesser / gist:3371206
Created August 16, 2012 15:47
backbone model change
// Returns a hash of attributes whose current and previous value differ.
_changed : function(){
var attr, changes = {},
now = this.attributes,
old = this._previousAttributes || {};
var all = _.union(_.keys(now), _.keys(old));
// If the new and current value differ, record the change.
for (var i = all.length; i>=0; i--) {
@tgriesser
tgriesser / gist:3818951
Created October 2, 2012 13:06
multiple nested changes with silent
this case:
test("multiple nested changes with silent", 2, function() {
var changes = [];
var model = new Backbone.Model();
model.on('change:b', function(model, val) { changes.push(val); });
model.on('change', function() {
model.set({b: 1});
model.set({b: 2}, {silent: true});
});
test("#1664 - silent changes on changing attributes triggered by other attributes", 1, function() {
var changes = [];
var model = new Backbone.Model({a:'a', b:1, c:'item'});
model.on('change:a change:b change:c', function(model, val) { changes.push(val); });
model.on('change', function() {
model.set({a:'c'}, {silent:true});
});
model.change();
model.set({a:'a'}, {silent:true});
model.change();
var YourModel = Backbone.Collection.extend({
beforeDestroy:function () {
if (/*someLogic*/) {
this.destroy();
}
},
})
var YourCollection = Backbone.Collection.extend({
model: YourModel,
var BaseModel = Backbone.Model.extend({
destroy: function () {
if (!this.beforeDestroy || this.beforeDestroy() !== false) {
Backbone.Model.prototype.destroy.apply(this, arguments);
}
}
});
<script src="/socket.io/socket.io.js"></script>
<script src="/lib/q.js"></script>
<script>
var socket = io.connect('http://localhost');
</script>
// ...
<script>
var model = new SocketModel();
var Book = Backbone.Model.extend();
var book = new Book();
book instanceof Book // true
book instanceof Backbone.Model // true
var Relation = function () {};
Relation.extend = Backbone.Model.extend
var RelatedBook = Relation.extend(Book.prototype);
var relatedBook = new RelatedBook();