Skip to content

Instantly share code, notes, and snippets.

View berzniz's full-sized avatar

Tal Bereznitskey berzniz

View GitHub Profile
- (void)rulesAreForDouches {
if (!goodStuff) {
return;
}
if (badStuff) {
return;
}
[self doGood];
}
@berzniz
berzniz / gist:2025061
Created March 12, 2012 22:22
Backbone.js global notifications made easy
var FirstView = Backbone.View.extend({
initialize: function() {
Backbone.Notifications.on('SomeViewRendered', function (msg) {
alert(msg);
}, this);
}
});
var SecondView = Backbone.View.extend({
render: function() {
@berzniz
berzniz / gist:2045615
Created March 15, 2012 17:52
Adding a global notification system to backbone.js
Backbone.Notifications = {};
_.extend(Backbone.Notifications, Backbone.Events);
@berzniz
berzniz / gist:2594221
Created May 4, 2012 11:27
No booleans
if ((viewA.origin.y < viewB.origin.y) && (viewB.origin.y + viewB.size.height < viewA.origin.y + viewA.size.height)) {
[self doSomething];
}
@berzniz
berzniz / gist:2594243
Created May 4, 2012 11:28
With booleans
BOOL viewAcontainsViewB = (viewA.origin.y < viewB.origin.y) && (viewB.origin.y + viewB.size.height < viewA.origin.y + viewA.size.height);
if (viewAcontainsViewB) {
[self doSomething];
}
@berzniz
berzniz / gist:2900899
Created June 9, 2012 12:57
handlebars1
var rawTemplate = '<p>Hello {{name}}</p>'; // (step 1)
var compiledTemplate = Handlebars.compile(rawTemplate); // (step 2)
var html = compiledTemplate({ name : 'World' }); // (step 3)
// html content will now be: <p>Hello World</p>
@berzniz
berzniz / gist:2900902
Created June 9, 2012 12:59
handlebars2
var compiledTemplate = Handlebars.templates['hello'];
var html = compiledTemplate({ name : 'World' });
@berzniz
berzniz / gist:2900905
Created June 9, 2012 13:01
handlebars3
Handlebars.getTemplate = function(name) {
if (Handlebars.templates === undefined || Handlebars.templates[name] === undefined) {
$.ajax({
url : 'templatesfolder/' + name + '.handlebars',
success : function(data) {
if (Handlebars.templates === undefined) {
Handlebars.templates = {};
}
Handlebars.templates[name] = Handlebars.compile(data);
},
@berzniz
berzniz / gist:2900942
Created June 9, 2012 13:21
handlebars25
var compiledTemplate = Handlebars.getTemplate('hello');
var html = compiledTemplate({ name : 'World' });
initialize: function() {
// Observe changes to the model and call the render function when they happen
this.model.on('change', this.render, this);
// Render the view for the first time
render();
}
userMarkedObjectAsFavorite: function() {
// We're changing the mode, not the UI