This file contains hidden or 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
App.Models.Comment = Backbone.Model.extend(_.extend({}, App.Mixins.Ajax, { | |
urls: { | |
flag: '/comments/flag_comment/:id' | |
}, | |
flag: function(formData) { | |
this.set('is_flagged', true); | |
return this.ajax('flag', { | |
data: formData, | |
error: function() { |
This file contains hidden or 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 compileTemplates = function() { | |
_.each(App.Views, function(View) { | |
if (View.prototype.templateId) { | |
// The templateId references the id of a DOM element containing | |
// the content of the template | |
var html = jQuery('#' + View.prototype.templateId).html() || ''; | |
View.prototype.template = _.template(html); | |
} | |
}); | |
} |
This file contains hidden or 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 compose = function compose(f) { | |
var queue = f ? [f] : []; | |
var fn = function fn(g) { | |
if (arguments.length) { | |
queue.push(g); | |
return fn; | |
} | |
return function() { | |
var args = Array.prototype.slice.call(arguments); | |
queue.forEach(function(func) { |
This file contains hidden or 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
### | |
FooBar jQuery Plugin v1.0 - It makes Foo as easy as coding Bar (?). | |
Release: 19/04/2013 | |
Author: Joe Average <[email protected]> | |
http://github.com/joeaverage/foobar | |
Licensed under the WTFPL license: http://www.wtfpl.net/txt/copying/ | |
### | |
(($, window, document) -> |
This file contains hidden or 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 toArray(args) { | |
return [].slice.call(args); | |
} | |
function autocurry(fn) { | |
var len = fn.length; | |
var args = []; | |
return function next() { | |
args = args.concat(toArray(arguments)); | |
return (args.length >= len) ? |
This file contains hidden or 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
exports.update = function (accumulator, value) { | |
accumulator.n++; | |
var delta = value - accumulator.mean; | |
accumulator.mean += delta / accumulator.n; | |
accumulator.m2 += delta * (value - accumulator.mean); | |
}; | |
exports.variance = function (accumulator) { | |
return accumulator.m2 / (accumulator.n - 1) | |
}; |
This file contains hidden or 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
module Jekyll | |
class PostPublisher < Generator | |
safe false | |
def replace(filepath, regexp, *args, &block) | |
content = File.read(filepath).gsub(regexp, *args, &block) | |
File.open(filepath, 'wb') { |file| file.write(content) } | |
end | |
def generate(site) |
This file contains hidden or 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 (!Object.__proto__) { | |
var sandbox = function () { | |
// create an <iframe> | |
var iframe = document.createElement("iframe"); | |
iframe.style.display = "none"; | |
document.documentElement.appendChild(iframe); | |
return frames[frames.length - 1]; | |
} | |
var iframe = sandbox(); |
This file contains hidden or 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 sum (fn, xs) { | |
var toRet = 0; | |
for (var i = 0, ii = xs.length; i < ii; i++) { | |
toRet += fn(xs[i], i, xs); | |
} | |
return toRet; | |
} | |
function update(t, o) { | |
for (var k in o) { |
This file contains hidden or 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.prototype.runOnBackgroundThread = function (aCallback) { | |
var _blob = new Blob(['onmessage = '+this.toString()],{"type":"text/javascript"}); | |
var _worker = new Worker((webkitURL.createObjectURL || URL.createObjectURL)(_blob)); | |
_worker.onmessage = aCallback; | |
_worker.postMessage(); | |
} | |
var _test = function () { | |
postMessage((1+1).toString()); | |
} |