This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ModalView = Backbone.View.extend({ | |
tagName: 'p', | |
template: 'this is modal content', | |
render: function() { | |
this.$el.html(this.template); | |
return this; | |
} | |
}); | |
$(document).ready(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MainView = Backbone.View.extend({ | |
el: 'body', | |
events: { | |
'click #open': 'openModal' | |
}, | |
template: '<a id="open" class="btn">open modal</a>', | |
openModal: function() { | |
var view = new ModalView(); | |
var modal = new Backbone.BootstrapModal({ | |
content: view, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
function iterator(collection) { | |
var index = 0; | |
var length = collection.length; | |
function next() { | |
var item = collection[index++]; | |
return item; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fib(x) { | |
if (x < 2) | |
return 1; | |
return fib(x-1) + fib(x-2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!Function.prototype.curry) { | |
(function () { | |
var slice = Array.prototype.slice; | |
Function.prototype.curry = function () { | |
var target = this; | |
var args = slice.call(arguments); | |
return function () { | |
var allArgs = args; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// binding "this" object only (function arguments are ignored) | |
if (!Function.prototype.bind) { | |
Function.prototype.bind = function bind(thisObject) { | |
var fun = this; | |
return function() { | |
fun.apply(thisObject, arguments); | |
}; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// binding both "this" object and optionally arguments | |
if (!Function.prototype.bind) { | |
Function.prototype.bind = function bind(thisObject) { | |
var fun = this, boundArgs = Array.prototype.slice.call(arguments, 1); | |
return function() { | |
var allArgs = boundArgs; | |
if (arguments.length) { | |
allArgs = allArgs.concat(Array.prototype.slice.call(arguments)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define entries | |
entries = [{'type': '+', 'value': 9},\ | |
{'type': '+', 'value': 12.3},\ | |
{'type': '-', 'value': 4},\ | |
{'type': '+', 'value': 0.89},\ | |
{'type': '-', 'value': 2.65},\ | |
{'type': '-', 'value': 14.3},\ | |
{'type': '+', 'value': 6.8},\ | |
{'type': 'unknown', 'value': 200}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
start = time.clock() | |
for x in range(1,10000): | |
y = x**3 | |
elapsed = time.clock() - start | |
print elapsed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TemplateLoader = { | |
path: 'templates/', // template files are stored in this directory | |
templates: ['file1', 'file2', 'file3'], // put all your template files here | |
fetchTemplate: function(path) { | |
$.ajax({ | |
type: 'GET', | |
dataType: 'text', | |
async: false, | |
url: path | |
}).done(function(response) { |