Skip to content

Instantly share code, notes, and snippets.

View berzniz's full-sized avatar

Tal Bereznitskey berzniz

View GitHub Profile
- (void)viewDidLoad
{
[super viewDidLoad];
[self observeModel]
[self render];
}
- (void)observeModel
{
// KVO is used to observe model changes
//
// TBKeychainCounter.h
//
// Created by Tal Bereznitskey on 5/11/13.
// Copyright (c) 2013 Tal Bereznitskey. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface TBKeychainCounter : NSObject
Backbone.easyXDMxhr = new easyXDM.Rpc({
remote: 'http://foo.bar/cors/',
}, {
remote: {
request: {}
}
});
Backbone.ajax = function() {
var options = arguments[0];
NSString *command = @"ok glass, take a picture";
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:command];
[synthesizer speakUtterance:utterance];
var inline_test = function(func, inputs, expected_outputs) {
for (var i in inputs) {
var input = inputs[i];
var expected = expected_outputs[i];
var result = func(input);
if (result != expected) {
console.log('Test failed! Expected', expected, 'but got', result);
// Or throw an error...
}
}
@berzniz
berzniz / jshipster_and_and.js
Last active May 22, 2022 23:15
Some small javascript hacks for hipsters
// Boring
if (isThisAwesome) {
alert('yes'); // it's not
}
// Awesome
isThisAwesome && alert('yes');
// Also cool for guarding your code
var aCoolFunction = undefined;
@berzniz
berzniz / ChangeTrackableModel.js
Last active October 22, 2021 20:25
A model that "knows" if it has unsaved changes
// This model (and any other model extending it) will be able to tell if it is synced with the server or not
var ChangeTrackableModel = Backbone.Model.extend({
hasChangedSinceLastSync: false,
initialize: function() {
// If you extend this model, make sure to call this initialize method
// or add the following line to the extended model as well
this.listenTo(this, 'change', this.modelChanged);
},
@berzniz
berzniz / NSObject+Debounce.h
Created January 25, 2014 16:18
Debounce method for Objective C
@interface NSObject (Debounce)
- (void)debounce:(SEL)action delay:(NSTimeInterval)delay;
@end
@berzniz
berzniz / bind-unbind.js
Last active August 29, 2015 13:58
Backbone tips & rules
// Ok:
this.stateModel.on('change:readMore', this.renderReadMore, this);
// Awesome:
this.listenTo(this.stateModel, 'change:readMore', this.renderReadMore);
@berzniz
berzniz / 1.js
Last active August 29, 2015 14:04 — forked from anonymous/1.js
var model = new Backbone.Model({counter: 1});